Input Celsius and convert it to Farenheit

Oct 9, 2013 at 12:04am
hey guys, Im new to C++. I've tried to solve the problem but no luck. My code will be shown below. Please advice me where I went wrong. Thanks

Write a program that reads a Celsius degree in double, converts it to Farenheit, and displays the result. The formula for conversion is: farenheit = (9/5) * Celsius + 32;
(Note: 9/5 is 1 in C++, so you need to use 9.0/5)

#include <iostream>
using namespace std;

int main()
{
double C, F;

cout << "Welcome";
cout << "Enter the temperature in Celsius to convert it to Fahrenheit";
cin >> C
F = (9.0/5)*(C + 32);
system("pause");
return 0;

}
Oct 9, 2013 at 12:23am
Missing semi-colon at cin >> C. And if you want to display the result in your screen you need to cout it.
Oct 9, 2013 at 12:24am
For future reference, it always help when your provide a description of your problem.
In your case, the program will not compile because you are missing a ";"

See if you can find out where it is missing.
Oct 9, 2013 at 12:27am
Wow, I totally missed the semi colon ¬¬ thanks guys !
Oct 9, 2013 at 12:29am
Thanks, Locien how would I counter that?
Last edited on Oct 9, 2013 at 12:31am
Oct 9, 2013 at 12:32am
I said cout it, as in cout << something. ;)
Oct 9, 2013 at 12:33am
Ah right, I think I need to head to sleep after this because I saw 'count' ><
Oct 9, 2013 at 12:36am
#include <iostream>
using namespace std;

int main()
{
double C, F;

cout << "Welcome \n";
cout << "Enter the temperature in Celsius to convert it to Fahrenheit";
cin >> C;
F = (9.0 / 5)*(C + 32);
cout << F;
system("pause");
return 0;
}
Oct 9, 2013 at 12:39am
Got it working I think. How do I get the answer to be displayed away from the 'Press any key to continue'...

i.e.

Welcome
Enter the temperature in Celsius to convert it to Fahrenheit 10
75.6Press any key to continue...
Last edited on Oct 9, 2013 at 12:40am
Oct 9, 2013 at 12:59am
Next time place your code in [ code] blocks.

And this should make your answer show up on its own line.
cout << F << endl;
Topic archived. No new replies allowed.