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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
using namespace std;

double celsiusDegrees(double);

int main()
{
    double userInput,
           degrees;

    cout<<"Number: ";
    cin>>userInput;

    degrees = celsiusDegrees(userInput);

    cout<<degrees;
}

double celsiusDegrees(double num)
{
    double celsius;

    celsius = (num - 32) * (5/9);

    return celsius;
}


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:
1
2
3
4
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.