Apr 13, 2016 at 2:23am UTC
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 Apr 13, 2016 at 2:27am UTC
Apr 13, 2016 at 2:45am UTC
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.
Apr 13, 2016 at 2:53am UTC
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.