Good day. I was tasked to create a "list of programs" that will display all programs I created. At first I will the user for a password, and then if they input the incorrect password, the program will exit. That works fine, but the problem comes when they do input the correct password. I used switch case for this problem and had a while loop and another switch case inside the former switch case. The problem is, after inputting the correct password, C prints out the text but doesn't let me input anything, it just ends the program. Here is the code:
#include <stdio.h>
#include <string.h>
int main()
{
char name [64], program, prog1;
int password;
printf("Good day! What is your name? ");
scanf("%s", &name);
printf("Good day, %s! Please input the password for this program. ", name);
scanf("%i", &password);
switch(password) {
case 1234:
system("CLS");
printf("MENU OF PROGRAMS");
printf("\n(1) BMI Calculator ");
printf("\n(2) Program 2");
printf("\n(3) Program 3");
printf("Would you like to test my programs? Input Y or N: ");
scanf("%c", &prog1);
while (prog1=='Y') {
printf("\nInput desired program: ");
scanf("%i", &program);
system("CLS");
switch(program) {
case 1:
// Program 1
case 2:
// Program 2
case 3-10:
// Code
default:
system("color 2");
printf("Thank you for trying out my menu of programs! :)");
return 0;
}
}
break;
default:
printf("Incorrect Password.");
}
}
The code starting from the while loop was working fine until I added the option for inputting the password, the only inputs and outputs for this code are the ones asking for name and the password, but after I input the password, it only outputs this and does not let me continue further into the program:
MENU OF PROGRAMS
(1) BMI Calculator
(2) Program 2
(3) Program 3
Would you like to test my programs? Input Y or N:
--------------------------------
Process exited after 5.908 seconds with return value 10
Press any key to continue . . .
Is there any workaround for this? So far the only functions we're allowed to use are those included in the code. Any help will be greatly appreciated, thank you so much!