Celsius to Fahrenheit

Working on a school problem for celsius to fahrenheit requiring that I make a function that contains a for loop that will convert the two temperatures. I also need to create a table that lists the data from 0-20. I have my table created, and my for loop. I believe my calculation is correct but whenever the program is run I get 20 rows of 0s. I know the use of a function is pointless here but it is requested by my teacher. I’m thinking I have to do something to calculation to get the negative numbers to display. While this is basic keep in mind this is only my 3rd month of learning this language so constructive criticism on my code is welcome if you have a seemingly useful answer to the problem.

Edit: screwed everything up in creating this thread. Should be fixed now, forgive me its early.

[code=cpp]
/*
Program Name: Chapter5Program2
Chapter: Chapter 5
Pg# / Ex.: Pg. 201 Program 2
Programmer: Zach Marshall
Date: 3/23/2016
Description: Convert Fahrenheit to Celsius from 0 - 20 degrees by displaying a table. The formula for converting fahrenheit
to celsius is C = 5/9(F-32)
*/

#include
#include
using namespace std;

//function prototypes
double Celsius(int F);

int main()
{

//declare variables
double C;
int F = 0;

//sets decimal place to 2
cout << fixed << setprecision(2);

//setup output table
cout << "Fahrenheit\t" << "Celsius" << endl;
cout << "----------\t" << "-------" << endl;

//define C -- Celsius
C = Celsius(F);

cout << endl; //blank line
return 0;

}

double Celsius(int F)
{
double C;
double multiplier = 5 / 9;

for (F = 0; F <= 20; F++)
{
	//conversion
	C = multiplier * (F - 32);
	//displays the temperatures
	cout << F << "\t" << C << endl;
}

return C;

}[/code]

EDIT: Problem solved, teacher pointed out to me that it was a mistake that would smack you in the face.

must be changed to

because 5 / 9 is integer division and can’t be transformed into a double.

In the future, I’d suggest the following when writing a program like this:

[ul][li]Line 43, you calculate 5/9 every time you run your program. The value of 5/9 will never change, consider making it a constant in your program.[/li]
[li]You are combining the conversion and the printing of output in a single function - this makes things hard to modify. Create a single function that converts one temperature in Fahrenheit to Celsius, then create another function which creates tables and uses your conversion function. [/li]
[li]The value 20 on Line 45 could be a variable or a global constant so you can modify how big the table is![/li][/ul]

[quote=“Fat Cookies, post:2, topic:555036”]In the future, I’d suggest the following when writing a program like this:

[ul][li]Line 43, you calculate 5/9 every time you run your program. The value of 5/9 will never change, consider making it a constant in your program.[/li][/ul][/quote]

Yeah! I noticed this when I was rereading my code, it was just a simple mistake I overlooked because I tried to use the 5/9 straight in the formula. I just wanted to see if this would fix my issue.

[quote=“Fat Cookies, post:2, topic:555036”]In the future, I’d suggest the following when writing a program like this:

[ul][li]You are combining the conversion and the printing of output in a single function - this makes things hard to modify. Create a single function that converts one temperature in Fahrenheit to Celsius, then create another function which creates tables and uses your conversion function. [/li][/ul][/quote]

My teacher is very finicky about how we write our programs. The book calls for just one function and I wanted to use two, but I didn’t want to get a bad grade. :expressionless:

[quote=“Fat Cookies, post:2, topic:555036”]In the future, I’d suggest the following when writing a program like this:

[ul][li]The value 20 on Line 45 could be a variable or a global constant so you can modify how big the table is![/li][/ul][/quote]

I love this idea, but again my teacher almost forbids the use of global variables because of how they can change so easily throughout the program and screw up your output without giving you any errors at all.

Finally, I was hoping you could help with the problem, I should of pasted it. I’ll hop on my laptop and edit this and post the issue. Thank you for the constructive criticism though. I really appreciate it!

I love this idea, but again my teacher almost forbids the use of global variables because of how they can change so easily throughout the program and screw up your output without giving you any errors at all.

If it’s constant, there’s no risk.