Temperature conversion program, need help

I am new to programming and am having trouble grasping concepts with functions.

Here is my problem:
This program is to give the user the option of converting a set of temperatures either from Celsius to Fahrenheit (C to F) or vice versa, from Fahrenheit to Celsius (F to C), or to quit the program. If the user selects either C to F or F to C, the program will prompt the user to enter three integer values, a starting temperature, an ending temperature, and an increment. After these values have been entered the program will display a table of equivalent C and F (or F and C) temperatures, from the starting temperature to the ending temperature and incrementing by the increment value each row.
The table must meet all of the following criteria:
• The table's column headings should display the degree symbol, e.g., °C and °F.
• The first column must be the "from" temperature (C for C to F or F for F to C) and the second column the "to" temperature (F for C to F or C for F to C).
• The calculated "to" temperatures are to be displayed to the nearest tenth of a degree (display exactly one decimal place, even if there is no fractional part, i.e., 75° should display as 75.0°).
• Temperatures in both columns must be number-aligned (right-justified for the integer "from" values and decimal point aligned right for the "to" values).
• Assume the user enters correct data, e.g., the start temperature, end temperature and increment are all integers and the ending temperature is greater than the starting temperature.
here is 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
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
90
91
92
93
94
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>

using namespace std;

float CtoF(float);
float FtoC(float);
char displayMenu();				//displays a menu
char getMenuSelection(char);		/*gets the menu selection from the user,
								*upper or lower case 'C' for Celsius to 
								*Fahrenheit, upper or lowercase 'F' for
								*Fahrenheit to Celsius, and upper or 
								*lowercase 'Q' to quit. Any other input should
								*get an error message "Invalid selection: try again"
								*and re-prompt for the menu selection.*/
float getStartEndAndIncrement();	//gets the start, end, and increment values for the table

void displayTable();			/*displays a C to F or F to C table given start, end, and 
								*increment values and the conversion character the user selected.*/

int main ()
{
	char choice = displayMenu();
	char menu = getMenuSelection ();
	float degree = getStartEndAndIncrement ();
	float fTemp, cTemp;
	{
	if (menu == 'f' || menu =='F')
	{
		cTemp = FtoC(degree);
		fTemp = degree;
	}
	else if (menu == 'c' || menu == 'C')
	{
		fTemp = CtoF(degree);
		cTemp = degree;
	}
	else
		cout << "Invalid Selection: try again." << endl;
		exit (EXIT_FAILURE);
	}

	float startDeg, endDeg, increment;
	getStartEndAndIncrement(startDeg, endDeg, increment);
	
	
	displayTable(startDeg, endDeg, increment);

	cin.ignore(2);
	return 0;
}
char getMenuSelection(char choice)
{
	switch (choice)
	{
	case 'c':
	case 'C':
		{
			cout << "Enter temperature 
float getStartEndAndIncrement ()
{
	float startDeg;
	cout << "Enter starting temperature reading in degrees: " << endl;
	cin >> startDeg;

	float endDeg;
	cout << "Enter the ending temperature reading in degrees: " << endl;
	cin >> endDeg;

	float increment;
	cout << "Enter the increment for the displayed temperatures you want to see: " << endl;
	cin>> increment;
	return endDeg;
	return increment;
	return startDeg;
}
float FtoC (float fTemp)
{
	float cTemp;
	cTemp = (5. * (fTemp - 32.)) / 9.;
	return cTemp;
}
float CtoF (float cTemp)
{
	float fTemp;
	fTemp = (( 9. * cTemp) / 5.) + 32.;
	return fTemp;
}
void displayTable (float startDeg, float endDeg, float increment)
{
	cout << "Celsius" << "\t" << "Fahrenheit" << endl;
	cout << "
	for (float i = startDeg; i < end; i += increment)
	{
		cout << i << "\t" << CtoF(i) << endl;
	}
}
int displayMenu(int choice)
{
	cout << "MENU" << endl;
	cout << " C : Convert Fahrenheit to Celsius" << endl;
	cout << " F : Convert Celsius to Fahrneheit" << endl;
	cout << " Q : Quit program" << endl;
	cout << "Enter your choice: ";
	char choice;
	cin >> choice;
	return choice;
}


I think my biggest issue is how to organize all the functions, I know I have to create a function which gives the user three options, then I have to have another function which calls that functions' 'answer' and that's kind of where I am lost. I also realize that my table is currently setup incorrectly, I am working on getting that to adjust dependent on users' request as the 'from' temp must be on the right...

Only looking for guidance, not answers please and THANK YOU!
Last edited on
I think what I am looking for is help with my order of events.

In my mind I see it like this:
displayTable
//get values from user //(char or c, f, or q)
getMenuSelection //(c,f, or q)
//what else to do here is lost on me
...
...
void getStartEndAndIncrement(float &startDeg, float &endDeg, float &increment)
//ask user for values
CtoF()
//or
FtoC()
//getStart...increment(startDeg,...,increment)
//here I assume I need to create/use a loop to convert the values continuously throughout the increment...
...
displayTable(float startDeg, float endDeg, float increment)
//somehow set table to display celsius or fahrenheit on left column depending on temp from...
//perhaps
getMenuSelection(choice)
if (choice == 'c' || choice == 'C')
{
cout << //correct table...
for (float i = startDeg; i < end; i += increment)
{
cout << i << "\t" << CtoF(i) << endl;
}
}
else if (choice ==...)
{
cout << //opposite table...
for (float i = startDeg; i < end; i += increment)
{
cout << i << "\t" << CtoF(i) << endl;
}
}

I know the code above(first post) is VERY ugly, I am just hesitant on wiping it all out as it has taken me a LONG time to get even that far...
Ok, I think I have made some progress....

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>

using namespace std;

float CtoF(float);					//converts values
float FtoC(float);
char displayMenu();					//displays a menu
char getMenuSelection(char);		/*gets the menu selection from the user,
									*upper or lower case 'C' for Celsius to 
									*Fahrenheit, upper or lowercase 'F' for
									*Fahrenheit to Celsius, and upper or 
									*lowercase 'Q' to quit. Any other input should
									*get an error message "Invalid selection: try again"
									*and re-prompt for the menu selection.*/
void getStartEndAndIncrement();		//gets the start, end, and increment values for the table

void displayTable();				/*displays a C to F or F to C table given start, end, and 
									*increment values and the conversion character the user selected.*/
void displayMenu(char choice)
{
	cout << "MENU" << endl;
	cout << " C : Convert Fahrenheit to Celsius" << endl;
	cout << " F : Convert Celsius to Fahrneheit" << endl;
	cout << " Q : Quit program" << endl;
	cout << "Enter your choice: ";
	cin >> choice;
	getMenuSelection(choice);
}
void getMenuSelection()
{
	getStartEndAndIncrement();
}
void getStartEndAndIncrement (float &startDeg, float &endDeg, float &increment)
{
	float startDeg;
	cout << "Enter starting temperature reading in degrees: " << endl;
	cin >> startDeg;

	float endDeg;
	cout << "Enter the ending temperature reading in degrees: " << endl;
	cin >> endDeg;

	float increment;
	cout << "Enter the increment for the displayed temperatures you want to see: " << endl;
	cin>> increment;
}


int main ()
{
	displayMenu();
	char choice = getMenuSelection ();
	float degree = getStartEndAndIncrement ();
	float fTemp, cTemp;
	{
	if (menu == 'f' || menu =='F')
	{
		cTemp = FtoC(degree);
		fTemp = degree;
	}
	else if (menu == 'c' || menu == 'C')
	{
		fTemp = CtoF(degree);
		cTemp = degree;
	}
	else
		cout << "Invalid Selection: try again." << endl;
		exit (EXIT_FAILURE);
	}

	float startDeg, endDeg, increment;
	getStartEndAndIncrement(startDeg, endDeg, increment);
	
	
	displayTable(startDeg, endDeg, increment, choice);

	cin.ignore(2);
	return 0;
}



float FtoC (float fTemp)
{
	float cTemp;
	cTemp = (5. * (fTemp - 32.)) / 9.;
	return cTemp;
	
}
float CtoF (float cTemp)
{
	float fTemp;
	fTemp = (( 9. * cTemp) / 5.) + 32.;
	return fTemp;
}
void displayTable (float startDeg, float endDeg, float increment, char choice)
{
	if (choice == 'c' || choice == 'C')
	{
		cout << "Celsius" << "\t" << "Fahrenheit" << endl;
		cout << "-------" << "\t" << "----------" << endl;
	}
	else if (choice == 'f' || choice == 'F')
	{
		cout << "Fahrenheit" << "\t" << "Celsius" << endl;
		cout << "----------" << "\t" << "-------" << endl;
	}
	for (float i = startDeg; i <= endDeg; i += increment)
	{
		cout << i << "\t" << CtoF(i) << endl;
	}
}
Perhaps I am in the wrong discussion forum?
Topic archived. No new replies allowed.