Question:
WHY DOESNT MY SWITCH WORKK
Current behavior:
I SWEAR IM DOING IT RIGHT
Desired behavior
ITS LIKE NOT SHOWING UP FOR SOME REASONNNN THE 1 AND 2 WHEN I INPUT THE COMMAND SEND HELP
Repl link:
https://replit.com/@blushiinme/VigilantScalyAssembly
code snippet
Mr-PP5
2
Multiple issues with your code
- Line 15 scanf(“d%” you have the percentage sign on the wrong side.
- Your switch cases are looking for a string instead of a numeric
- Your char variables for username and password need to use an array to store the string correctly.
Below is the modified code:
#include <stdio.h>
#include <unistd.h>
int main(void) {
printf("Opening App...\n");
sleep(2);
printf("\nYour virtual floral boutique for easy browsing, personalized bouquets, and convenient flower delivery.\n");
sleep(2);
puts("\n1. Log in");
sleep(1);
puts("2. Sign up");
sleep(1);
int options;
scanf("%d", &options);
switch(options) {
case 1:
printf("\nEnter your username: \n");
char username[50];
scanf("%s", username);
printf("Enter your password: \n");
char password[50];
scanf("%s", password);
break;
case 2:
printf("\nEnter your username: \n");
char username2[50];
scanf("%s", username2); s
printf("Enter your password: \n");
char password2[50];
scanf("%s", password2);
break;
}
return 0;
}
2 Likes