I'm a few months into taking C++ and this is my hardest assignment so far. I've read my book and gone to tutoring, but I'm just having too much trouble trying to figure out how to make a char function and calling it.
A function named menu that returns a character and does not accept any parameters. This function will display:
Welcome to <your name>’s Space Travel Company
M)ost Powerful Calculation
D)iscount Calculation
H)ow Many Calculation
Q)uit
I tried making a char function and it turned out like this:
#include <iostream>
using namespace std;
char menu();
int main ()
{
menu();
system("PAUSE");
return 0;
}
char menu()
{
cout << "Welcome to Natalie’s Space Travel Company!" <<endl;
cout << endl;
cout << "(M)ost Powerful Calculation" << endl;
cout << "(D)iscount Calculation" << endl;
cout << "(H)ow Many Calculation" << endl;
cout << "(Q)uit" << endl;
cout << "Please enter the option (M,D,H, or Q): ";
Hi :) For you char menu, is a function that requires to return a char. So you will need to return a char. In order to do that, you have to add a variable. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
char menu()
{
char option; // to be returned
cout << "Welcome to Natalie’s Space Travel Company!" <<endl;
cout << endl;
cout << "(M)ost Powerful Calculation" << endl;
cout << "(D)iscount Calculation" << endl;
cout << "(H)ow Many Calculation" << endl;
cout << "(Q)uit" << endl;
cout << "Please enter the option (M,D,H, or Q): ";
cin >> option; // get user's input
return option; // return user's input
}
Then at your main, you will have: char option = menu(); .