Please support our C++ advertiser: Programming Forums
Views: 1276 | Replies: 2
![]() |
•
•
Join Date: Mar 2005
Posts: 90
Reputation:
Rep Power: 4
Solved Threads: 1
so im trying to write this program that converts Fahrenheit to Celsius and vice versa but im gettin an infinate loop at the menu. i go to select the number that i want and it just displays the menu again, i though i was doin it right?
<< moderator edit: added [code][/code] tags >>
#include <iostream> //for cin and cout
#include <iomanip>
#include <cmath>
using namespace std;
void main()
{
double C, //Celsius
F;//Fahrenheit
int choice; //Number for choice
#define cls ("cls") // clear system
#define pause ("pause") // pause system
do
{
cout << "Select one the the following options: \n\n";
cout << " 1. Temperature conversion from Fahrenheit to Celsius: \n\n"
<< " 2. Temperature conversion from Celsius to Fahrenheit: \n\n"
<< " 3. Quit the program now: \n" << endl;
cin >> choice;
switch (choice)
{
case '1': cout << "Enter the degrees in Fahrenheit: \n\n";
cin >> F;
C = 5 / 9 * ( F - 32 );
cout << "The conversion is: " << C << endl;
break;
case '2': cout << "Enter the degrees in Celsius: \n\n";
cin >> C;
F = 9 * C / 5 + 32;
cout << "The conversion is: " << F << endl;
break;
case '3': cout << "Program closed" << endl;
break;
}
}
while (choice != '3');
} Since choice is an int, compare it with 1, 2, and 3 -- not with characters '1', '2', and '3'.
High Plains Blogger #plains #lounge ## I, for one, welcome our new socialist overlords.
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
"Capitalism is the unequal distribution of wealth. Socialism is the equal distribution of poverty."
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode