Stop loop inside of switch
Hey guys, was wondering how would I end this loop. In my Shutdown case switch.
For some reason it keeps looping at shutdown, I have no idea what I'm doing wrong.
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
#include <iostream>
using namespace std;
#include "Commands.h"
#include "Enumerations.h"
#include "Party.h"
#include "Plane.h"
#include "ReadFunctions.h"
#include "ReadString.h"
#include "Numbers.h"
void main ()
{
bool everything;
bool alfabegin (false);
bool bravobegin (false);
bool arrive (false);
bool loungebegin (false);
bool illegal (false);
bool alfaarrive (false);
bool bravoarrive (false);
bool loungearrive (false);
bool end (false);
Commands Cmd;
Plane Alfa;
Plane Bravo;
Plane Lounge;
Party ArrivingParty;
Party Temp;
PlaneID GetPlaneID ();
PlaneID WhichPlane;
char * party;
int a (0);
int b (0);
int l (0);
int i (0);
do
{
everything = true;
cout <<"Enter commands. (Alfa, Bravo, Lounge, Arrive, Fly, Shutdown)" << endl;
cout << endl;
Cmd = ReadCommand ();
switch (Cmd)
{
case ALFA:
if (!alfabegin)
{
cout << "Enter amount of seats." << endl;
Alfa.NumSeats = ReadInteger();
Alfa.NumEmptySeats = Alfa.NumSeats;
Alfa.NumParties = 0;
Alfa.Parties = new Party [Alfa.NumSeats];
alfabegin = true;
}
break;
case BRAVO:
if(!bravobegin)
{
cout << "Enter amount of seats." << endl;
Bravo.NumSeats = ReadInteger();
Bravo.NumEmptySeats = Bravo.NumSeats;
Bravo.NumParties = 0;
Bravo.Parties = new Party [Bravo.NumSeats];
bravobegin = true;
}
break;
case LOUNGE:
if (!loungebegin)
{
cout << "Enter amount of seats." << endl;
Lounge.NumSeats = ReadInteger();
Lounge.NumEmptySeats= Lounge.NumSeats;
Lounge.NumParties = 0;
Lounge.Parties = new Party [Lounge.NumSeats];
loungebegin = true;
}
break;
case ARRIVE:
cout<<"What is the name of this party?" << endl;
ArrivingParty.Name = ReadString ();
cout <<"How many people are in this party?" << endl;
ArrivingParty.HowMany = ReadInteger ();
cout << "Which plane will they board?" << endl;
ArrivingParty.WhichPlane = GetPlaneID ();
switch (ArrivingParty.WhichPlane)
{
//////
case ALFA:
if (Alfa.NumSeats >= ArrivingParty.HowMany)
{
if (Alfa.NumEmptySeats >= ArrivingParty.HowMany)
{
Alfa.NumEmptySeats -= ArrivingParty.HowMany;
(Alfa.Parties [Alfa.NumParties++] = ArrivingParty);
cout << ArrivingParty.Name << " is boarding plane Alfa." << endl;
break;
if (Alfa.NumEmptySeats == 0)
{
Fly (Alfa);
{
cout <<"Done Flying." << endl;
Alfa.NumEmptySeats = Alfa.NumSeats;
for (a = 0; a < Alfa.NumParties; a++)
{
delete [] Alfa.Parties[i].Name ;
}
Alfa.NumParties = 0;
break;
}
if (Lounge.NumParties >0)
{
for (l =0; l < Lounge.NumParties; l++)
if ((Lounge.Parties[l].WhichPlane) == PlaneAlfa)
{
if (Alfa.NumEmptySeats >= Lounge.Parties [l].HowMany)
{
Alfa.NumEmptySeats -= Lounge.Parties [l].HowMany;
Alfa.NumParties++;
Alfa.Parties [Alfa.NumParties].Name = Lounge.Parties [l].Name;
Lounge.NumEmptySeats += Lounge.Parties [l].HowMany;
for (b = l; b < Lounge.NumParties; b++);
{
Lounge.Parties [l].Name = Lounge.Parties[a+1].Name;
}
Lounge.NumParties --;
break;
}
}
}
}
break;
}
else
{
cout <<"Sent to lounge" << endl;
if ((Lounge.NumEmptySeats) >= (ArrivingParty.HowMany))
{
Lounge.NumEmptySeats -= ArrivingParty.HowMany;
(Lounge.Parties [Lounge.NumParties++] = ArrivingParty);
break;
}
else
cout << "No more room in lounge, bye." << endl;
}
}
break;
//*******
case BRAVO:
if ((Bravo.NumSeats) >= (ArrivingParty.HowMany))
{
if ((Bravo.NumEmptySeats) >= (ArrivingParty.HowMany))
{
Bravo.NumEmptySeats -= ArrivingParty.HowMany;
(Bravo.Parties [Bravo.NumParties++] = ArrivingParty);
cout << ArrivingParty.Name << " is boarding plane Bravo." << endl;
break;
}
if (Bravo.NumEmptySeats == 0)
{
Fly (Bravo);
{
cout <<"Done Flying." << endl;
Bravo.NumEmptySeats = Bravo.NumSeats;
for (a = 0; a < Bravo.NumParties; a++)
{
delete [] Bravo.Parties[i].Name ;
}
Bravo.NumParties = 0;
break;
}
if (Lounge.NumParties >0)
{
for (l =0; l < Lounge.NumParties; l++)
if ((Lounge.Parties[l].WhichPlane) == PlaneBravo)
{
if (Bravo.NumEmptySeats >= Lounge.Parties [l].HowMany)
{
Bravo.NumEmptySeats = Lounge.Parties [l].HowMany;
Bravo.NumParties++;
Bravo.Parties [Bravo.NumParties].Name = Lounge.Parties [l].Name;
Lounge.NumEmptySeats += Lounge.Parties [l].HowMany;
for (b = l; b < Lounge.NumParties; b++);
{
Lounge.Parties [l].Name = Lounge.Parties[a+1].Name;
}
Lounge.NumParties --;
break;
}
}
}
}
break;
}
else
{
cout <<"Sent to lounge" << endl;
if ((Lounge.NumEmptySeats) >= (ArrivingParty.HowMany))
{
Lounge.NumEmptySeats -= ArrivingParty.HowMany;
(Lounge.Parties [Lounge.NumParties++] = ArrivingParty);
break;
}
else
cout << "No more room in lounge, bye." << endl;
break;
}
}
break;
//********************************************************************************************************
case FLY:
cout << "Which plane will be flying?" << endl;
ArrivingParty.WhichPlane = GetPlaneID ();
Fly ( Alfa );
break;
case SHUTDOWN:
do
{
cout << "Shutting down." << endl;
end=false;
if (Alfa.NumParties)
{Fly (Alfa);}
if (Bravo.NumParties)
{Fly (Bravo);}
if (Lounge.Parties)
{
for (a = 0 ; a < (Lounge.NumParties) ;a++)
{
ArrivingParty.WhichPlane = Lounge.Parties[a].WhichPlane;
ArrivingParty.Name = Lounge.Parties[a].Name;
ArrivingParty.HowMany = Lounge.Parties[a].HowMany ;
}
}
if((!Alfa.NumParties)&&(!Bravo.NumParties)&&(!Lounge.NumParties))
{end=true;}
}
while (!end);
everything = false;
exit (0);
break;
case BAD_CMD:
cout << "Illegal command entered" << endl;
cout << "Enter another command." << endl;
break;
default:
cout << "Should not be here." << endl;
}
}
while (everything);
}
|
Last edited on
Topic archived. No new replies allowed.