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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#include <string>
#include <iostream>
#include <stdlib.h>
#include<cctype>
using namespace std;
void display(int & choice);
void first(int & choice, bool seats[], char & anwser, int & fcseats, int & counter, int & scseats);
void second(int & choice, bool seats[], char & anwser, int & scseats, int & counter, int & fcseats);
const int T_seats = 10;
const int MAXFCSEATS{ 5 };
int main()
{
char anwser;
int fcseats, counter, scseats;
counter = 0; // SET COUNTER TO 0 HERE!
int choice;
bool seats[T_seats] = { false };
do {
display(choice);
first(choice, seats, anwser, fcseats, counter, scseats);
second(choice, seats, anwser, scseats, counter, fcseats);
} while (toupper(anwser) == 'Y');
}
void display(int & choice)
{
cout << "Welcome! Press 1 for first class or 2 for economic" << endl;
cin >> choice;
}
void first(int & choice, bool seats[], char & anwser, int & fcseats, int & counter, int & scseats)
{
int wanted;
if (choice == 1)
{
//counter = 0;//setting it to zero COMMENTED OUT THIS LINE
cout << "Welcome to first class!" << endl;
cout << "seats 1-5 are available" << endl;
do {
cout << "pick a seat" << endl;
cin >> wanted;
counter++;//adding one to everytime I put in a seat or a least it is supposed to
std::cout << '\n' << counter << '\n';
if (wanted < 1 || wanted>5)
cout << "Wrong number input" << endl;
} while (wanted < 1 || wanted>5);
if (!seats[wanted])
{
seats[wanted] = true;
}
else
{
cout << "Seat is taken. Choose another seat number." << endl;
}
while (counter > 5)//The following is supposed to happen after the 5th input for a seat
{
cout << "First class full would you like to go in economy? Press Y or N" << endl;
cin >> anwser;
if (toupper(anwser) == 'Y')
{
second(choice, seats, anwser, scseats, counter, fcseats);
}
else
{
cout << "Next flight is in 3 hours" << endl;
exit(1);
}
}
cout << "Do you want to go again? Press Y for yes or N for no" << endl;
cin >> anwser;
}
}
void second(int & choice, bool seats[], char & anwser, int & scseats, int & counter, int & fcseats)
{
int wanted;
if (choice == 2)
{
cout << "Welcome to Economy!" << endl;
cout << "seats 6-10 available" << endl;
do {
cout << "pick a seat" << endl;
cin >> wanted;
if (wanted < 6 || wanted>10)
cout << "Wrong number input" << endl;
} while (wanted < 6 || wanted>10);
if (!seats[wanted])
{
seats[wanted] = true;
}
else
{
cout << "Seat is taken. Choose another seat number." << endl;
}
cout << "Do you want to go again? Press Y for yes or N for no" << endl;
cin >> anwser;
}
}
|