loops

(The formula for converting a temperature from Fahrenheit to Celsius is
C=5/9(F-32)
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 converted Celsius temperature.
Demonstrate the function is correct by calling it in a loop that displays a table of the Fahrenheit temperature 0 through 20 and their Celsius temperature equivalents)



I am really confused over loops please help me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <iostream>
#include <iomanip>
using namespace std;
double celsius(double fahrenheit)
{
double celsius;
celsius = 5 * (fahrenheit - 32) / 9;
return celsius;
}
int main()

{

int tempCount=20;

cout<<setw(20)<<"fahrenheit"<<setw(20)<<"celsius"<<endl;
for (int count = 1; count <= tempCount; count++)
{
cout<<setw(20)<<count<<setw(20)<<celsius(count)<<endl;
}
system("pause");
return 0;

}
i also made
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
double celsius(int);
int main()
{int t;
cout<<"Fahrenheit\tCelsius\n";
for(t=0;t<=20;t++)
    cout<<t<<"\t\t"<<celsius(t)<<endl;
system("pause");
return 0;
}

double celsius(int F)
{return 5./9.*(F-32.);
}
closed account (E0p9LyTq)
Other than starting your loop at 1 instead of the instructed 0, your code is correct.
thank you for verifying <3
Topic archived. No new replies allowed.