| Tiger58 (22) | |||
My brain doesn't seem to be working right now. I have no idea what the hell I am doing wrong, this is just a part of a code I am trying to figure out
It just keeps returning 0s and negative 0s. I am sick. I don't know what is going on with this. What am I overlooking? Perhaps I need to go to bed | |||
|
|
|||
| LowestOne (895) | |
@line 23 you are doing integer division: 5/9. The result will be an integer, zero. Make one of them a double: 5.0/9
| |
|
|
|
| Tiger58 (22) | |
|
Damn it, I knew the problem was there but...wasn't it suppose to truncate it or something anyway? Ah nevermind I see, it gets truncated at the division itself, seems like I still have some to study | |
|
Last edited on
|
|
| LowestOne (895) | |||
This is allowed:
| |||
|
Last edited on
|
|||
| princesslumy (36) | |
|
better version of convertion of temperature // Convertion of degree Celcius to Farenheit #include<iostream> #include<cstdlib> #include<cmath> using namespace std; int main() { cout<< "Enter temperature."<<endl; double F,C; double temp; cin>> temp; cout<<"Enter F if temperature is Fahrenheit; or C if the temperature is in Celsius"<<endl; double tempType; cin >> tempType; if (tempType == 'C') //Convert from Celcius to Fahrenheit { cout<< "The equivalent of temperature in Fahrenheit is"<<(9.0/5.0)*C + 32<<endl;} else if( tempType == 'F') //Convert from Fahrenheit to Celcius { cout<< "The equivalent of temperature in Celsius is"<<(F-32)*(5.0/9.0)<<endl;} else //invalid choose to calculate cout<< "Invalid choose has been entered"<< endl; system("PAUSE"); return 0; } | |
|
|
|