I think maybe you were supposed to enclose the whole process in a single while loop.
I was about to mention the reasons for some of your problems but MagicDark pointed them out.
I think maybe you were supposed to use something like this.
I took your code and just moved it around a bit.
By the way , copying and pasting blocks of code is quicker, but easier to miss the changes you need to make, like was mentioned, you forgot the conversions, and I believe the both said Fahrenheit ..
I didn't finish up your conversions, or straighten up everything, Just figured if you got up and running you could sort the rest out as you go.
anyway check this out and see if it makes more sense.
a few less while loops.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
char choice ;
double tempToConvert;
cout << "This program converts a temperature from one scale to the other." << endl;
cout << "Choose one of the following ..." << endl;
cout << " C: to convert from Celsius to Fahrenheit" << endl;
cout << " F: to convert from Fahrenheit to Celsius" << endl;
cout << " Q: to quit" << endl;
cout << "Enter your choice: ";
cin >> choice;
cout << '\n';
while (choice != 'q' && choice != 'Q') // exit if user enters q or Q
{
if (choice == 'F' || choice == 'f')
{
cout << "Enter the Fahrenheit temperature to convert: ";
cin >> tempToConvert;
cout << tempToConvert << " degrees Fahrenheit is " << ((tempToConvert-32)/1.8)
<< " degrees Celsius. " << endl ;
}
if (choice == 'C'|| choice == 'c')
{
cout << "Enter the Celsius temperature to convert: ";
cin >> tempToConvert;
cout << tempToConvert << " degrees Celsius is " << " degrees Celsius. " << endl;
}
else
cout << endl << choice << " is not a valid choice." << endl;
cout << endl;
cout << "This program converts a temperature from one scale to the other." << endl;
cout << "Choose one of the following ..." << endl;
cout << " C: to convert from Celsius to Fahrenheit" << endl;
cout << " F: to convert from Fahrenheit to Celsius" << endl;
cout << " Q: to quit" << endl;
cout << "Enter your choice: ";
cin >> choice;
} // end while loop
|
I think he's using the system pause just to keep the window open when he runs it from an IDE.