temperature home work

>Celsius Temperature Table
The formula for converting a temperature from Fahrenheit to Celsius is
where F is the Fahrenheit temperature and C is the Celsius temperature. Write a function
named celsius that accepts a Fahrenheit temperature as an argument. The function
should return the temperature, converted to Celsius. Demonstrate the function by
calling it in a loop that displays a table of the Fahrenheit temperatures 0 through 20
and their Celsius equivalents.

book: Starting out with c++

this is what i have so far, can any one please help me out...

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
29
30
31
#include "stdafx.h"
#include<iostream>
using namespace std;
double celsius

double celsius(double );

void main()
{ 
     double F=0,C;
cout<<"------------------------------"<<endl;
cout<<"Farenheit\t Celsius"<<endl;
cout<<"------------------------------"<<endl;

for(int i=0; i<=20;i++)
{
        C = celsius(F);
        cout<<F<<"\t\t"<<C<<endl;
        F++;
        }
        system("pause");
        }
        
        
        double celsius(double F)
        
        {
               double temp;
               temp = ((5.0/9.0)*(F-32));
               return temp;
               }
Well the errors that c++ gives me when I enter the code are: you're missing a semicolon on line 4, and then redeclaring that on line 6. Also " local function definitions are illegal". Does it specify what kind of loop you need, I think a do-while loop would be better than a for loop in this case.
What is it that you're having trouble with? Don't just throw the problem at us with your half-assed attempt and expect us to finish it for you. And we can't do much for you when all you basically say is "I'm having trouble with this code. HALP!"
You're off to a good start. Line 4 is unnecessary (as well as invalid without a ";").

You're also not connecting your loop index ("i") to your variable F. Adding an assignment within the loop will make the program work as desired.

mzimmers wrote:
You're off to a good start.


Unless you count void main() or the definition of celsius() the formatting. Hopefully that code doesn't compile on any compiler...

EDITED
Last edited on
The comment about the void main is valid. Celsius() isn't defined within main(), though...it only looks that way because of his odd indentation.
Topic archived. No new replies allowed.