I am a beginner and I am taking my first C++ programming class. We are using an IDE named Codeblocks and I am stumped. I have searched the forums for an answer but I just cannot figure it out on my own.
I am trying to figure out why my code is not exiting when entering 3 in the menu on command prompt. Also I am trying to figure out why when I am trying to convert fahrenheit to celsius my formula is not working, when I believe it is the correct formula.
The code is below:
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main ()
{
float celsius;
float fahrenheit;
char x;
//Menu for user to choose which option they would like to
//preform. Also looping in case they type in the incorrect
// response and would like to choose again.
do
{
cout << "Please choose an option. Then please press Enter. \n";
cout << "1. Convert Celsius to Fahrenheit.\n";
cout << "2. Convert Fahrenheit to Celsius. \n";
cout << "3. Exit Program \n";
cin >> x;
if (x == '1')
system ("cls");
{
cout << "Please enter degrees in Celsius. \n";
cin >> celsius;
system ("cls");
fahrenheit = 9.0 / 5 * celsius + 32;
//Calculate the formula for converting Celsius to Fahrenheit.
cout << fixed << showpoint << setprecision(2);
cout << fixed << "The degrees in Fahrenheit is \n" << fahrenheit;
cout << static_cast<char>(248) << endl;
cout << "Thank you have a great day!";
(x = '3');
}
// User does not want to convert Celsius to Fahrenheit
// Since user does not want to convert, display a Thank you message.
if (x == '2')
{
cout << "Please enter degrees in Fahrenheit. \n";
cin >> fahrenheit;
celsius = (fahrenheit - 32) * 5.0 / 9 ;
//Calculate the formula for converting Fahrenheit to Celsius.
cout << fixed << showpoint << setprecision(2);
cout << fixed << "The degrees in Celsius is \n" << celsius;
cout << static_cast<char>(248) << endl;
cout << "Thank you have a great day!";
(x = '3');
} while (x != '3')
return 0;
}
}