RE: [Dev-C++] temperture converter problem-help needed
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From:
<igo...@po...> - 2000-12-14 10:55:23
|
Hi,
If you remove the ";" after else than your program should work
the way you want. You could also change your program
so that you do the reading of data in a loop.
Regards
Igor Pierscinski
-----Original Message-----
From: J R [ mailto:ray...@ya... <mailto:ray...@ya...> ]
Sent: Thursday, December 14, 2000 3:50 AM
To: dev...@li...
<mailto:dev...@li...>
Subject: [Dev-C++] temperture converter problem-help needed
ok I'm trying to make a simple celcius, farenheit converter. I want it to
ask which you want to convert to, what temperature, and then convert. I
already have everything working prefectly except that I ask the user to type
in what to convert to. The way I have it if they type 1 it converts celcius
to farenheit and 2 farenheit to celcius. Now heres the problem. I want it
so that if a user types any number but 1 or 22 it says "invalid entry" I
have that working too but if the user picks to type in 1 to convert celcius
to farenheit right after he puts in his number it converts it and then says
invalid entry. I dont want it to say invalid entry there. Only if the user
types in something besides 1 or 2. Heres the code any help would be great.
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
int main()
{
while(1)
{
string type;
cout << "Would you like to convert to Celcius or Farenheit?" <<endl;
cout << " " <<endl;
cout << "1. Farenheit" <<endl;
cout << " " <<endl;
cout << "2. Celcius" <<endl;
cout << " " <<endl;
cin >>type;
if (type== "1")
{
unsigned short int tempc;
cout << " " <<endl;
cout << "Please enter the Celcius temperature you wish to convert."<<endl;
cin>> tempc;
cout << " " <<endl;
unsigned short int degreefarenheit=tempc*9/5+32;
cout << " " <<endl;
cout << "Temperature in Farenheit:" << degreefarenheit <<endl;
cout << " " <<endl;
}
if (type== "2")
{
unsigned short int tempf;
cout << " " <<endl;
cout << "Please enter the farenheit temperature you wish to convert."<<endl;
cin >> tempf;
cout << " " <<endl;
unsigned short int degreecelcius=tempf-32*5/9;
cout << " " <<endl;
cout << "Temperature in Celcius:" << degreecelcius <<endl;
cout &l! t;< " " <<endl;
}
else;
{
cout << "Invalid entry please try again" <<endl;
}
system("PAUSE");
}
return 0;
}
If you could rewrite it for me or just tell me what I did wrong it would be
greatly appreciated.
Thanks again,
J
_____
Do You Yahoo!?
Yahoo! <http://shopping.yahoo.com/> Shopping - Thousands of Stores.
Millions of Products.
|