jeudi 4 février 2016

Confused with nested if-else and strcmp

What's wrong with my code? The login system works fine but it won't let me choose what to do. This code was originally from here, I just edited it. Any ideas on how I can fix and improve this? I'm using Turbo C v2.0 compiler.

#include<stdio.h>
#include<conio.h>
#include<string.h>

main()
{
char choice;
char username[20];
char password[20];
clrscr();

printf("Enter username: ");
scanf("%s",username);

printf("Enter password: ");
scanf("%s",password);

if (strcmp(username, "user") == 0 && strcmp(password, "pass") == 0)
{
    printf("Access granted!\n");
    printf("\nWhat do you want to do?\n");
    printf("\nA. Display info\n");
    printf("B. Exit\n");

    printf("\nEnter your choice: ");
    scanf("%c",&choice);

        if (choice=='A'){
            printf("Name: KarsTimesTen");
                }
        else if (choice=='B'){
            printf("Exiting....\n");
                     }
}
else{
    printf("Access denied!\n");
    }

getch();
}

Aucun commentaire:

Enregistrer un commentaire