### WHAT IS GOING ON.

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

 ``1234567891011121314151617181920212223242526`` ``````#include using namespace std; double celsiusDegrees(double); int main() { double userInput, degrees; cout<<"Number: "; cin>>userInput; degrees = celsiusDegrees(userInput); cout<

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
@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`
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
This is allowed:
 ``1234`` ``````double celsiusDegrees(double num) { return (num - 32) * (5.0/9); }``````
Last edited on
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;
}
Topic archived. No new replies allowed.