Solved! nested switch case example in c programming (please help)

Status
Not open for further replies.
Oct 30, 2018
2
0
10
Write a C code that ask the user to enter his ID, if the ID is valid it will
ask the user to enter his password, if the password is correct the
program will print the user name, if the password is incorrect the
program will print Incorrect Password.
In case of not existing ID, the program will print Incorrect ID


(using switch case)
this is my code please help I cannot get the required

#include <stdio.h>

void main(void)
{
int ID;
int pass;
printf("Plese Enter Your ID: ");
scanf("%d",&ID);
printf("Enter your password: ");
scanf("%d",&pass);
switch(ID)
{
case 470:
printf("Welcome Mahmoud");
break;
switch(pass)
{
case 602:
printf("Welcome Mahmoud");
}
default :
printf("incorrect password");
break;
}

}



 

rgd1101

Don't
Moderator


run in debug. figure it out
 
Dec 20, 2018
1
0
10
I have slightly amended your code based on the provided instructions
C++:
#include <stdio.h>
int main()
{
int ID=400;
int pass=123;
printf("Plese Enter Your ID:\n ");
scanf("%d",&ID);
switch(ID)
{
case 400: 
printf("Enter your password:\n ");
scanf("%d",&pass);
	switch(pass)
	{
	case 123:
	printf("Welcome Mahmoud\n");
	break;
	default :
	printf("incorrect password"); 
	break;
	}
break;
default :
printf("incorrect ID"); 
break;
}
}
 
Status
Not open for further replies.

TRENDING THREADS