### Celcius Temperature Table

 ``123456789101112131415161718192021222324252627282930313233343536373839`` ``````// Includes #include "stdafx.h" #include #include using namespace std; // Prototypes double farhenheit(); // Farhenheit Table Function double farhenheit() { int x; double conversion; cout << "F \t C" << endl; cout << "_______________" << endl; for ( x = 0 ; x <= 20 ; x++ ) { conversion = x * -17.22; cout << x << " \t " << endl; } _getch(); return conversion; } // Main Function int main() { cout << "This will automatically display a farhenheit to celcius table from 0-20.\n\n"; farhenheit(); _getch(); return 0; }``````

Don't worry this isn't homework, im teaching myself c++ more in depth due to the fact i only took a year of it in school.

The exercise from the ebook reads:

The formula for converting a temperature from Farhenheit to Celcius is where F is the Farhenheit temperature and C is the Celcius temperature. Write a function that accepts a farhenheit temperature as and argument. The function should return the temperature, converted to celcius. Demonstrate the function bby calling it in a loop that displays a table of the ferhenheit temperatures 0-20 and their celcius equivalents.

I want to make sure i am doing this right, can anyone look and see please. I have a feeling im not even close to doing this right.
Last edited on
In the exercise there is written "Write a function that accepts a farhenheit temperature as and argument. The function should return the temperature, converted to celcius". So you should write a function that accepts a Farhenheit temperature and returns a corresponding Celcius. Your function shall not contain any other code except this calculation.
Last edited on
 Write a function that accepts a farhenheit temperature as and argument.

Do you know what they mean by argument?

The function declared below does not have an argument.
 ``12`` ``````// Prototypes double farhenheit();``````

This is not correct:
`conversion = x * -17.22;`

I would move everything that you have in your function (except the return statement) in to main. And have your function just do the proper conversion. Call your function in the loop.
ok thank you
 ``1234567891011121314151617181920212223242526272829303132`` ``````// Includes #include "stdafx.h" #include #include using namespace std; // Prototypes int celcius(int , int); // Farhenheit Table Function int celcius(int x, int conversion) { for ( x = 0 ; x <= 20 ; x++) { conversion = x - 32 * ( 5 / 9 ); } return conversion; } // Main Function int main() { cout << "This will display the farhenheit to celcius conversion table from 0-20.\n\n"; for ( int x = 0 ; x <= 20 ; x++ ) { cout << x << " \t " << celcius << endl; } _getch(); return 0; }``````

ok heres my new code everything works except all the celcius temperatures say

013514B0

anyone know why.

That's the address of the celcius function. Perhaps you should actually call the function?
Because that's the address to your function. I take it you're pretty new to programming.

`cout << x << " \t " << celcius << endl;`

This does not call the function. If you want to a call a function, do this:

`foo(arg)`
Well im not like new new to programming its just usually i dont do like ex. return conversion, usually i dont do anything like that bu i got to learn it. but thank you
If you aren't familiar with functions, then you're pretty new to programming. They're a fundamental part of programming.
lol i mean the return part confused me, i know functions, just not whena have a return value of like my program its return conversion, usually i do like return 1 or return 0. also usually i dont make any args usually i just user int celcius() or void celcius(), not int celcius (int x, int conversion)
 ``1234567891011121314151617181920212223242526272829303132333435363738`` ``````// Includes #include "stdafx.h" #include #include using namespace std; // Prototypes int celcius(int x); // Farhenheit Table Function int celcius(int x) { int conversion; for ( x = 0 ; x <= 20 ; x++) { conversion = ( x -32 ) * (5 / 9); } _getch(); return conversion; } // Main Function int main() { cout << "This will display the farhenheit to celcius conversion table from 0-20.\n\n"; cout << "Farhenheit \t Celcius\n\n"; for ( int x = 0 ; x <= 20 ; x++ ) { cout << x << " \t\t " << celcius(x) << endl; } _getch(); return 0; }``````

Everything works now, heres my fixed code, but all the conversion numbers are showing up as 0, anyone know why.
Integer division. 5/9 is 0.

` conversion = ( x -32 ) * (5.0 / 9);`
when i change it to that i get all -6 and a warning saying line 17

warning conversion from double to int, possible loss of data, i even get that warning when i change conversion from int to double.
Well, I would expect the warning about the conversion. You can safely ignore it in this case if you don't want the decimal places showing and don't mind a bit of a rounding error.

What is the for loop doing in the celcius function?
Topic archived. No new replies allowed.