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

Oct 30, 2018
2
0
10
0
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;
}

}



 
Dec 20, 2018
1
0
10
0
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;
}
}
 

rgd1101

Polypheme
Moderator


run in debug. figure it out
 
Thread starter Similar threads Forum Replies Date
E Apps General Discussion 2
henrytcasey Apps General Discussion 3
C Apps General Discussion 1
3 Apps General Discussion 1
D Apps General Discussion 9
junii Apps General Discussion 1
M Apps General Discussion 1
V Apps General Discussion 1
I Apps General Discussion 1
T Apps General Discussion 2
S Apps General Discussion 1
G Apps General Discussion 0
R Apps General Discussion 4
K Apps General Discussion 3
R Apps General Discussion 7
S Apps General Discussion 1
T Apps General Discussion 4
C Apps General Discussion 3
K Apps General Discussion 2
eodeo Apps General Discussion 1

ASK THE COMMUNITY