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?

Recommended Answers

All 3 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.