I got another question, when I try to execute the following:
Code:
#include <stdio.h>
#include <string.h>
void Login()
{
char uname[20];
char pwd[20];
int accNum;
printf("\n\tLogin to see your Bank Account\n");
printf("\t Enter Account Username: ");
scanf("%[^\n]%*c", uname);
printf("\n\t Enter Password: ");
scanf("%[^\n]%*c", pwd);
printf("\n\t Enter Account Num (required): ");
scanf("%d", &accNum);
printf("\n\tYou entered '%s' for username", uname);
printf("\n\tYou entered '%s' for password", pwd);
printf("\n\tYou entered '%d' for account number", accNum);
}
int main()
{
printf("\033[2J"); // clears the terminal
printf("\033[H"); // move cursor home
printf("\n\tWelcome to the Bank Management System\n");
printf("\t 1. Login to your account\n");
printf("\t 2. Create new account\n\n");
int choice;
printf("\n\n\tEnter your choice: ");
scanf("%d", &choice);
if(choice == 1)
{
printf("\033[2J"); // should also clear the screen.
printf("\033[H"); // move cursor home
Login();
}
else if(choice != 1 || choice != 2)
{
printf("You must enter either 1 or 2");
}
return 0;
}
I get the following:
If I enter 1, I get the following:
But consider the following code:
Code:
#include <stdio.h>
#include <string.h>
void Login()
{
char uname[20];
char pwd[20];
int accNum;
printf("\n\tLogin to see your Bank Account\n");
printf("\t Enter Account Username: ");
scanf("%[^\n]%*c", uname);
printf("\n\t Enter Password: ");
scanf("%[^\n]%*c", pwd);
printf("\n\t Enter Account Num (required): ");
scanf("%d", &accNum);
printf("\n\tYou entered '%s' for username", uname);
printf("\n\tYou entered '%s' for password", pwd);
printf("\n\tYou entered '%d' for account number", accNum);
}
int main()
{
Login();
return 0;
}
The I get the following:
Why is it that when I try to execute the Login() function in an if statement, It skips the enter username and password part and does to the enter account num part?