-
Celcius
Im trying to compile a program for a book
heres my code
Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgz[])
{
int celsius;
cout <<"Enter The Temperture in Celcius:";
cin >> celsius;
int factor;
factor - 212 - 32;
int fahrenhiet;
fahrenhiet - factor * celsius/100 + 32;
cout <<"Fahrenhiet value is:";
cout << fahrenhiet << endl;
system("pause");
return 0;
}
It complies and opens fine but it dosen't work it seems that the math is wrong. If i type in 0 Celcius i get 4198592
HELP!!!!!!!!
-
what are the errors?
this should be one: factor - 212 - 32
also initialize yourvars to 0, or something else. Factor should probably be a fraction, I forget what it is; 4/9 or something like that, and it should be stored in a double or a float; same with fahrenhiet.
this should be another error: fahrenhiet - factor * celsius/100 + 32;
I believe you want :fahrenhiet = factor * celsius/100 + 32;
-
You never initialize or assign to your variables.
Both lines:
Code:
factor - 212 - 32;
...
fahrenhiet - factor * celsius/100 + 32;
Do nothing. Perhaps those first '-'s ought to be '='. ;)
It will also be wrong because you are using integer arithmetic and not floating point arithmetic.
[ edit ] Rats! Beaten. [ /edit ]