Temperature

Hi guys! Just having a small problem. This code is not running right and im wondering what is the problem.


#include <iostream>
#include <stdlib.h>
using namespace std;

int main()

{
double C;
double F;
int a;

cout<<"Value the temperature with Celcius";
cin>>C;

F=1,8*C+32;

cout<<"The temperature in Fahrenheit is"<< F <<endl;


}
closed account (E0p9LyTq)
F = 1.8 * C + 32;, not F=1,8*C+32;.

PLEASE, use code tags, it makes reading your source easier.
http://www.cplusplus.com/articles/jEywvCM9/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <stdlib.h>

int main()

{
   double C;
   double F;

   std::cout << "Value the temperature with Celcius: ";
   std::cin >> C;

   F = 1.8 * C + 32;

   std::cout << "The temperature in Fahrenheit is " << F << std::endl;
}
Last edited on
closed account (48T7M4Gy)
1.8 not 1,8
This is how I would write it

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
double C;
double F;

cout << "Value the temperature with Celcius: ";
cin >> C;

F = 1.8 * C + 32;

cout << "The temperature in Fahrenheit is: " << F << endl;
}

What you did wrong is you wrote the f thing wrong you did
F = 1,8 * C + 32;
You have to do
F = 1.8 * C + 32;
Also I added
using namespace std;
So then you don't need to do the std:: thing.
Last edited on
Thanks guys! I appreciate your answers very much! :) The problem was just the little dot xD
inspiringnoob wrote:
Also I added
using namespace std;
So then you don't need to do the std:: thing.


That is actually a bad idea - Google to see why, there is plenty written on this site and on the internet.

What FurryGuy did is the right way of doing it, and you may notice that all the experienced people do it this as well - look at posts by JLBorges for example.

Btw, you should also investigate using code tags.

http://www.cplusplus.com/articles/jEywvCM9/


One final thing for the OP as well - always initialise your variables - even if you assign something to it on the next line. Not initialising things is a very big source of errors, not only for beginners - but also for some not so beginners.

Hope all goes well :+)
Last edited on
Topic archived. No new replies allowed.