I'm just going to start with the first thing I see that I don't like.
Your function input_choice has a parameter that makes no sense (you just write over it), and also it seems to return either an int OR a char. While you can cast a char to an int, don't. Pick one. What does this function do? PICK ONE THING THIS FUNCTION DOES.
#include<iostream>
#include<iomanip>
#include<string>
usingnamespace std;
// my prototypes
void print_menu();
int input_choice();
char input_type();
int input_age();
double compute_rate();
int input_reservation();
void print_all();
int main()
{
int menuChoice;
int userAge;
input_choice();
input_age();
return 0;
}
void print_menu() // Printed as a void since nothing to return for this
{
cout << "Please pick from the following menu" << endl;
cout << "1. Add a new reservation" << endl;
cout << "2. Print all reservations" << endl;
cout << "3. Print all reservations for a given sport" << endl;
cout << "4. Quit" << endl;
}
int input_choice()
{
int choice;
print_menu();
cin >> choice;
if (choice == 1)
{
input_type();
}
return choice;
}
char input_type()
{
char sport;
cout << "Please enter f/F for flying, g/G for gliding and h/H for hang-gliding" << endl;
cin >> sport;
input_age();
return sport;
}
int input_age()
{
int userAge;
cout << "Please enter the age of the patron, minimum 16" << endl;
cin >> userAge;
compute_rate();
return userAge;
}
double compute_rate()
{
double patronRate;
char sport = input_type();
int userAge = input_age();
if (((userAge >= 21) && (sport == 'F')) || ((userAge >= 21) && (sport == 'f')))
{
patronRate = 68.95;
cout << "The insurance rate is $" << patronRate << endl;
}
return patronRate;
}
I fixed the first problem, but I'm having trouble with how to fix the while loop - I've tried adding an if statement into input_choice and it didn't work
Do you have any ideas as to why choice isn't being initialized?