I have been programming a C program for few days now, however I have met some problems that I am unable to solve.
My code is:
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
int main()
{
char user_type;
printf("Welcome to XYZ Bank\n\n\n\n");
printf("Hint: a for admin and c for customer\n");
printf("Please input your account type (c/a):");
scanf("%c",&user_type);
system("cls");
if (user_type=='c')
{
customer_login();
}
else if (user_type=='a')
{
admin_login();
}
else if (user_type!='c' || user_type!='a')
{
printf("Invalid selection is made, the program will restart");
main();
}
}
The problem that I faced is when the user_type
is not 'a'
or 'c'
, the program is supposed to restart the main()
, however all it does is to continue printing invalid selection.
Is there some command that allows me to restart main()
? or is there a better way to do things? I think that a do while loop can be applied but I am not sure about it.
I am aware that the problem lies in the 3rd statement of my else-if loop, it would be helpful if somebody gave me tips on where to start.