I'm a beginner when it comes to programming and recently my professor asked me to make a program for the parking lot. The problem I'm facing is that when my compiler encounters a continue statement inside my switch statement, it doesn't transfer the control to the starting of the loop where the user is required to choose an option.
Here's my code:-
#include <iostream>
#include <string.h>
#include <fstream>
#include <vector>
int rick_amnt = 100, car_amnt = 200, busses_amnt = 300;
int car_parked = 0;
using namespace std;
int main()
{
int type, menu;
char confirm;
do {
cout << "-------MENU--------\n";
cout << "01 : Parking tickets" << endl;
cout << "02. Parked cars" << endl;
cout << "Choose an option : ";
cin >> menu;
system("cls");
if (menu == 1) {
cout << "01: Rickshaw\n02: Car\n03: Bus\n";
cout << "what is your car type : ";
cin >> type;
switch (type) {
case 1: {
cout << "Rickshaw parking ticket = " << rick_amnt << endl;
cout << "do you wish to park your Rickshaw?(y/n) ";
cin >> confirm;
if (confirm == 'y') {
cout << "Successfull payment!" << endl;
car_parked++;
break;
}
else {
cout << "Car parking declined" << endl;
continue;
}
}
case 2: {
cout << "Car parking ticket = " << car_amnt << endl;
cout << "do you wish to park your Car? (y/n) ";
cin >> confirm;
if (confirm == 'y') {
cout << "Successfull payment!" << endl;
car_parked++;
break;
}
else {
cout << "Car parking declined" << endl;
continue;
}
}
case 3: {
cout << "Buses parking ticket = " << busses_amnt << endl;
cout << "do you wish to park your Bus?(y/n) ";
cin >> confirm;
if (confirm == 'y') {
cout << "Successful payment!" << endl;
car_parked++;
break;
}
else {
cout << "Car parking declined" << endl;
continue;
}
}
default:
cout << "invalid identity" << endl;
}
}
else if (menu == 2) {
cout << "Parked cars = " << car_parked << endl;
}
else
cout << "Invalid entry" << endl;
cout << "Ty again?(y/n) ";
cin >> confirm;
system("cls");
} while (confirm == 'y');
cout << "Successfully exited the parking lot.\nHave a nice day!" << endl;
return 0;
}
I want my code to function in a way that if the user inputs any other character besides 'y' when asked to confirm parking, the parking is declined and control is transferred to the beginning of the loop where user should choose an option again. But, when I input any other character, my code just ends all the lines of code and exits the loop. Isn't the continue statement supposed to transfer the control towards the beginning of the loop?