Function Help

I've been trying to figure this out for a few hours now send help pls.
Its suppose to be a simple miles to kilometers with functions.

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
double milesToKilometers();
double kilometersToMiles();
void showMenu();
char getMenuChoice();
int main()
{
	char choice;
	do
	{
		showMenu();
		getMenuChoice();
		switch (toupper(choice))
		{
		case 'A':
			cout << milesToKilometers() << endl;
			break;
		case 'B':
			cout << kilometersToMiles() << endl;
			break;
		case 'Q':
			cout << "Closing" << endl;
			break;
		default:
			cout << "Not Valid" << endl;
			break;
		}
	}while (choice != 'Q');
	return 0;
}
double milesToKilometers()
{
	cout << "Enter Miles:" << endl;
	double m;
	cin >> m;
	m = m * 1.6093;
	return m;
}

double kilometersToMiles()
{
	cout << "Enter Kilometers: " << endl;
	double k;
	cin >> k;
	k = k * .6214;
	return k;
}
void showMenu()
{
	cout << "A. Miles to Kilometers" << endl;
	cout << "B. Kilometers to Miles" << endl;
	cout << "Q. Quit" << endl;
	return;
}
char getMenuChoice()
{
	char choice;
	cout << "Enter Choice: " << endl;
	cin >> choice;
	return choice;
}
Last edited on
I'm new to c++ too, and I don't think you cin>k ( or cin>>m) in the functions, same as cout<<... You are suppose to do it in main() and pass the values to the appropriate functions.
The whole point of the assignment was to use functions like this. Everything works except for the getMenuChoice. I just cant get it to work with the switch.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int main()
{
    char choice;

    do
    {
        showMenu();

        // getMenuChoice();
        choice = toupper( getMenuChoice() ) ;

        // switch (toupper(choice))
        switch(choice)
        {

// ... 
THANK U THIS WORKED!!
Topic archived. No new replies allowed.