Thursday, September 14, 2017

C++ Code Review: Showing Celsius or Fahrenheit degrees

Description: This program shows how to draw menu and convert Celsius to Fahrenheit or vice versa. Uses switch case to draw menu.

Code:

//Compiling Tool: Code::Block IDE with MinGW

//Program displays converted value from C to F or F to C.

 

#include<iostream>

#include<conio.h> //for getch()

#include<math.h>  //for sqrt()

#include<cstdlib> //for system()

 

using namespace std;

 

int main()

{

    float temp,result;

    int ch;

 

top:system("cls");//to clear the screen

 

    cout << endl;

    cout<<"***Temperature Converter Program***"<< endl;

    cout<<"   1. Celsius to Fahrenheit"<< endl;

    cout<<"   2. Fahrenheit to Celsius"<< endl;

    cout<<"   3. Quit"<< endl;

    cout<<"Enter your Choice:_";

    cin>>ch;

 

    if(ch > 3)

        cout<<"   Enter valid choice:_" ;

 

    switch(ch)

    {

    case 1:

    {

        cout<<"Enter temperature in Celsius:";

        cin>>temp;

        result=(temp*1.8)+32;

        cout << temp << " Degree Celsius = " << result << " Fahrenheit";

        break;

    }

 

    case 2:

    {

        cout<<"Enter temperature in Fahrenheit";

        cin>>temp;

        result=(temp-32)/1.8;

        cout << temp << " Fahrenheit = " << result << " Degree Celsius";

        break;

    }

 

    case 3:

    {

        cout<<"   Quitting the program"<< endl;

        exit(0);

    }

    default:

        goto top;

    }

 

    getch(); //to stop the screen

    goto top;

}

Output:

clip_image002

If you want to write or construct or program C++ mini-project and do not know how or from where to start buy this simple e-book: Code Review of 26 C++ mini-projects. For book sample click this link.

Add your comments in below available comment box.

Note: Click these label/tags to view all related posts. Tags: C++Code

 

…till next post, bye-bye & take care.

No comments:

Post a Comment