Temperature Conversion Program Errors

I have an assignment to write a program dealing with temperature conversion.I have to prompt the user for the scale and degree to be used and display both F and C equivalents of the temperature provided, rounded to two decimal places. If inappropriate input is provided for both scale and temperature, an error message needs to be displayed. I also need to include a temperature scale stating that appropriate temperatures are any values greater than or equal to absolute zero, -459.67F or -273.15C. I don't understand where I need to place this scale within my program. I also have an error coming up regarding my setprecision in the void getReusults function (line 84). My output is also incredibly off. If anyone could take a look at my program and provide me with any feedback/guidance, it would be GREATLY appreciated!

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <cstdlib>
using namespace std;

void programOverview ();
char getScale ();
float getDegree ();
float convertFtoC (float);
float convertCtoF (float);
void getResults ();

int main ()
{
  programOverview ();
  float degree = getDegree ();
  char scale = getScale();
  float Ftemp, Ctemp;
  {
  if (scale == 'F')
    {
     Ctemp =  convertFtoC(degree);
     Ftemp = degree;
    }
  else if (scale == 'C')
    {
     Ftemp =  convertCtoF(degree);
     Ctemp = degree;
    }
  else
    cout << "ERROR: Invalid temperature scale" << endl;
    exit (EXIT_FAILURE);
  }
  getResults(Ftemp, Ctemp);

  return 0;
}

//This function displays a brief overview explaining the program to the user
void programOverview ()
{
  cout << "This program will convert a temperature reading provided in" << endl;
  cout << "either Fahrenheit or Celsius to the other measurement scale." << endl;
}

//This function requires the user to enter the temperature scale to be used
char getScale ()
{
  char scale;
  cout << "Enter the letter of the temperature scale that will be used:" << endl;
  cout << "F = Fahrenheit; C = Celsius)" << endl;
  cin >> scale;
  return scale;
}

//This function requires the user to enter the temperature reading in degrees
float getDegree ()
{
  float degree;
  cout << "Enter your temperature reading in degrees:" << endl;
  cin >> degree;
  return degree;
}

//This function converts a Fahrenheit temperature to Celsius
float convertFtoC (float Ftemp)
{
  float Ctemp;
  Ctemp = (Ftemp - 32) / 1.8;
  return Ctemp;
}

//This function converts a Celsius temperature to Fahrenheit
float convertCtoF (float Ctemp)
{
  float Ftemp;
  Ftemp = 1.8 * Ctemp + 32;
  return Ftemp;
}

//This function displays the results
void getResults (float Ftemp, float Ctemp)
{
  cout << "Your temperature reading converts as follows:" << endl;
  cout << setprecision (4);
  cout << "Fahrenheit:" << Ftemp << endl;
  cout << setprecision (4);
  cout << "Celsius:" << Ctemp << endl;
}
For the setprecision, you need to include #<iomanip>. Also, you have stray curly brace at line 18. You need curly braces after line 29 to go with the curly brace at line line 32.
Last edited on
Okay, great! Thank you so much.

I am getting errors on lines 11 and 34 and am unsure as to what they mean...
11: error: too many arguments to function `void getResults()'
34: error: at this point in file
Wrong function prototype: change line 10 to:
void getResults (float, float);

Convert char 'scale' (in main) to uppercase, before if statment, or you will get errors when entering small 'f' / 'c'
Last edited on
Works perfectly! Thank you for your help! I really really appreciate it! :)
Topic archived. No new replies allowed.