Temperature conversion program.

brentmcgehee (12)
I need help again guys. I am working on a program to convert temperatures. This is what we are supposed to do.

The program needs to convert Fahrenheit to Centigrade, show both sets of temperatures in tabular form, and get the average of both sets of temperatures. Here's what I have so far.
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
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;


int main()

{

float F;

float C;

sumf=0, sumc=  0;

int count = 0;

cout << "Enter Fahrenheit temperature to continue. Enter -9999999 to stop.: ";

while(f!= 9999999)
     {

Count++;

cin >> F;

C= (5.0/9.0) * (F-32)

out.setf(ios::fixed);

Cout.setf(ios::showpoint);

Cout.precision(1);

cout<<”Ft = “<<Fahrenheit<< setw=10

Cout<<”C = “<<Centigrade<< setw=23

<<”avg fahrenheit =”<<sumf/count<<;
<<”avg centigrade =”<<sumc/count<<;
return 0;


I know it's a bit messy, but I wanted to leave room inbetween the lines for commments.
Chervil (1203)
Lots of things to straighten out here.
There is no closing brace for the while loop, nor for function main.
Mixture of uppercase and lowercase text. C++ is case sensitive.
Line 13, variables are used but have not yet previously been defined.
around lines 34-39 missing or misplaced semicolon.
setw() is misused.

Forget the blank lines, indentation is more important.
Last edited on
brentmcgehee (12)
This is my updated version. I think I am still missing stuff. BUt here.

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
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;


int main()

{

float F;

float C;

sumf=0, sumc=  0;

int count = 0;

cout << "Enter Fahrenheit temperature to continue. Enter -9999999 to stop.: ";

while(f!= 9999999)
     {

count++;

cin >> F;

c= (5.0/9.0) * (F-32)

out.setf(ios::fixed);

cout.setf(ios::showpoint);

cout.precision(1);

cout<<”Ft = “<<Fahrenheit<< setw()=10

Cout<<”C = “<<Centigrade<< setw()=23

<<”avg fahrenheit =”<<sumf/count<<;
<<”avg centigrade =”<<sumc/count<<;
return 0;}
closed account (17ihb7Xj)
Take another look at Chervil's post. You have two variables in line 13, but have not declared them. When declaring variables, you need to define them with a type, such as float, int, char, etc. I can also see that you want to use sumf and sumc for getting the average temperatures. However, the only thing you do with these variables (while they are not declared) is divide them by count. You are not setting those values to anything, so your average temperatures are always going to be 0, unless you write a section of code that will keep track of the sum of the values.

Something like this may work
1
2
3
4
5
6
7
//Declare the variables
float sumf, sumc = 0;

//Do some stuff here in code

sumc += C
sumf += F


You will also need to close that while loop and main function like Chervil pointed out. I would suggest using a do{} while() loop, to ensure that you're code gets executed at least once.

You are using the function setw() incorrectly as well.

Be careful with the names of your variables, C++ is case sensitive. It will also help you, and others, understand your code if you were to use more descriptive variables. For example sumc could be renamed to centigradeSum, sumf to fahrenheitSum, etc.

And I agree with Chervil, try to eliminate blank lines, and instead use the tab key to indent lines of code
brentmcgehee (12)
This is what I have done so far. I guess I'm just dumb when it comes to this stuff, I'm just not getting it.
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
#include <iostream>
#include <iomanip>
using namespace std;
int main()
  {
    float f;
    float c;
   float sumf=0, sumc=0;
    int count =0;
    cout << "Enter Fahrenheit temperature to continue. Enter -9999999 to stop. ";
      while(f!= 9999999)    
      {count++;
      cin >> f;
      c= (5.0/9.0) * (f-32);
   }
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(1);
    cout<<”f = “<<Fahrenheit<< setw(10);
    Cout<<”C = “<<Centigrade<< setw(23);
  <<”avg fahrenheit =”<<sumf/count<<setw(10);
  <<”avg centigrade =”<<sumc/count<<(23):
 system("pause")
return 0;}
}
Registered users can post here. Sign in or register to post.