I was going to post this in the beginners forum, but the sticky said to not post things not suitable for beginners.
I've picked up a guide for learning to program in C++, and it has an example code to convert celsius to fahrenheit.
In an effort to grasp the concepts better I want to make this code ask me for the temperature, and then ask if it is fahrenheit or celsius. Depending on my response I want it to do the conversions and spit out the opposite unit. I'll paste the original code, since what I've done doesn't work.
int main(int nNumberofArgs, char* pszArgs[])
{
int celsius;
cout << "Enter the temperature in Celsius:';
cin >> celsius;
int fahrenheit;
fahrenheit = celsius * 9/5 + 32;
cout << "Fahrenheit value is :";
cout << fahrenheit << endl;
system("PAUSE")
return 0;
>
I think I need to use an if/else but I can't figure out how to get the code to look at what I've typed and assign the number to the int celsius or int fahrenheit.
//...
char temp = 0;
cout<<"Please enter c for celsius or f for farenheit: ";
cin>>temp;
switch(temp)
{
case'c':
//do temperture conversion for celsius
break;
case'f':
//do temperture conversion for farenheit
break;
}
//output the temperature to the user
//hold the window open
return 0;
try to get away from using system("pause"). It is not cross platform, and tends to generate virus warnings.