Functions Help

I'm trying to make a simple menu-driven application that calculates miles to kilometers and vice versa. It won't compile due to errors towards the bottom of the program. No matter what I do I can't fix them. What's up here? Thanks in advance!

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
#include <iostream>
#include <string>

using namespace std;

double milesToKilometers(double miles);
double kilometersToMiles(double kilometers);
char getMenuChoice(char choice);

char choice, Q;

int main()
{
     do {
        cout << "Welcome to the Distance Conversion Caculator! " << endl;

        char getMenuChoice(char choice);
        } while (choice != Q);

  return 0;
}


    char getMenuChoice(char choice)
    {
            cout << "Main Menu" << endl;
            cout << "A. Miles to Kilometers" << endl;
            cout << "B. Kilometers to Miles" << endl;
            cout << "Q. Quit" << endl;
            cin >> choice;

    switch (choice)

        {
            case 'A':
            double miles;

                cout << "Enter Miles: ";
                cin >> miles;

                double milesToKilometers(double miles);

            break;

            case 'B':
                double kilometers;

                cout << "Enter Kilometers: ";
                cin >> kilometers;

                double kilometersToMiles(double kilometers);

            break;

            default:
                cout << "That is not a valid input. Please try again." << endl;
        }
    }

double milesToKilometers(double miles)
  {
    for (double x = miles; double y = x / 2; y / 2; double z = x + y)
    cout << z << endl;
  }

double kilometersToMiles(kilometers)
  {
    for (double x = kilometers; double y = x / 5; double z = y * 8)
    cout << z << endl;
  }
char getMenuChoice(char choice);
This is a function prototype and not a function call.
You also don't return anything in the function definition, which is necessary when you have a return type.

char choice, Q;
Don't use global variables. Instead pass them as arguments to your functions.

for (double x = miles; double y = x / 2; y / 2; double z = x + y)
What are you trying to do here?
You don't need a loop to convert between units.
1
2
3
4
double milesToKilometers(double miles)
{
    return miles * 1.609344;
}
Thank you so much! I forgot about the "return" command. Hehe. I won't do it again, that's for sure!
Topic archived. No new replies allowed.