Trouble with C++

Hello, this is my first post, and also my first week of programming.

I am trying to make a program that involves temperatures. When I try to convert from degrees F to Celsius, the value (Cels) is always a 0. Any hints or help would be great. Thanks.

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
27
28
  #include <iostream>
#include <cmath>
using namespace std;

int main()
{
	double  temp;
	double  wind;
	double NWC;
	double OWC;


	cout << "Enter the current temperature in faherenheit \n";
	cin >> temp;
	cout << "Enter the current wind speed in mph \n";
	cin >> wind;
	NWC = 35.74 + 0.6215*temp - 35.75*(pow(wind, 0.16)) + 0.4275*temp*(pow(wind, 0.16));
	NWC = round(NWC);
	OWC = .081*(3.71*sqrt(wind) + 5.81 - .25*wind)*(temp - 91.4) + 91.4;
	OWC = round(OWC);
	double Cels = (temp - 32)*(5 / 9);
	
	cout << "Temp:" << temp << " degrees Fahrenheit \n";
	cout << "Temp:" << Celc << " Centigrade \n";
	cout << "New wind chill formula:" << NWC << "\n";
	cout << "Old wind chill formula:" << OWC << "\n";
	
}
I think your problem is line 21

double Cels = (temp - 32)*(5 / 9);

try changing it to

double Cels = (temp - 32)*(5.0 / 9.0);

or

double Cels = (temp - 32)*5.0 / 9.0;
Last edited on
Wow, now I feel dumb. -_-

It worked, thanks mate.
I was making the same mistake a few weeks ago myself ;p

Basically all numbers are integer by default so if you divide a number it would round to nearest whole number.

You have to put a .0 or .f after the integer to make the compiler treat it as a float data type.
Topic archived. No new replies allowed.