this is my current code:

#include <iostream>
using namespace std;

	void celsius(double);

//Main
int main()
{
	cout << "Now displaying the first 20 fahrenheit temperatures and\n"
		<< "showing the Celsius equivalent.\n";

	//Loop for displaying the table
	for (int couter = 0; couter <= 20; couter++)
		celsius(couter);
	return 0;
}

//calculates and displays the celsius equivalent
void celsius(double fahren)
{
	double celsi;
	celsi = (5/9) * (fahren -32);
	cout << fahren << "\t\t" << celsi << "\n";
}

What im getting as an output is this:
Now displaying the first 20 fahrenheit temperatures and
showing the Celsius equivalent.
0 -0
1 -0
2 -0
3 -0
4 -0
5 -0
6 -0
7 -0
8 -0
9 -0
10 -0
11 -0
12 -0
13 -0
14 -0
15 -0
16 -0
17 -0
18 -0
19 -0
20 -0


What im looking to get is the correct value of celsius and not the string of "-0"
any ideas?

celsi = (5/9) * (fahren -32);

The problem is due to type conversion.
int/int will always yield int .

TY
i changed:
celsi = (5/9) * (fahren -32);

to:
celsi = (5.0/9.0) * (fahren -32);

and now everything's fine, =] woot

Good catch...just to emphasise.
example:

12/58 = 0

(integer arithmetic drops the fractional part). Welcome aboard too.

This article has been dead for over six months. Start a new discussion instead.