RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 1276 | Replies: 2
Reply
Join Date: Mar 2005
Posts: 90
Reputation: tyczj is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Why am i getting an infinate loop?

  #1  
Apr 6th, 2005
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?

#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');
}
<< moderator edit: added [code][/code] tags >>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,757
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 147
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Why am i getting an infinate loop?

  #2  
Apr 6th, 2005
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."
Reply With Quote  
Join Date: Mar 2005
Posts: 90
Reputation: tyczj is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 1
tyczj tyczj is offline Offline
Junior Poster in Training

Re: Why am i getting an infinate loop?

  #3  
Apr 6th, 2005
oh geez i never though about thanks makes sense now.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 4:47 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC