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 << " " <<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! Shopping - Thousands of Stores. Millions of Products. |