Here is my code.
(Goal) I want to ask a series of questions. The first is asking for a name, if the user inputs the name ‘William’ I want the program to proceed to ask for their birthdate. If that is answered correctly I want it to ask a series of yes or no questions. If the name ‘William’ is not entered, I want the program to re-ask for the users name until it is correct so it can proceed.
My issue is that every time I enter the name ‘William’ it will feed me back this response…
(put below my code)
#include <stdio.h>
#include <string.h>
int main()
{
char correctName[] = "William"; //This is the name that William will need to enter
char correctBirthday[] = "(01/01/2000)"; //This is the correct birthday he will need to enter
//The '100' represents how many character can be allowed in each questions answer
char name[100];
char birthday[100];
char response[10];
while (1) {
printf("Hello, please enter your name: ");
scanf("%s", name);
if (strcmp(name, correctName) == 0) {
printf("Thank you.n");
break;
} else {
printf("Searching... nnInvalid user. Please enter first and last name.nn");
}
}
while (1) {
printf("I must ask you to confirm your birthdate with me so I can assure that it is you.n");
printf("Please do so in this format: (MM/DD/YYYY). n");
scanf("%s", birthday);
if (strcmp(birthday, correctBirthday) != 0) {
break;
} else {
printf("Searching... nn");
printf("Invalid input. Only William is authorized to proceed. n");
}
}
printf("Hello William!nn");
printf("Do you wish to proceed? (yes/no): nn");
scanf("%s", response);
if (strcmp(response, "yes") == 0) {
printf("Great! lets get started.n");
}
else {
printf("Confirmed, have a nice day.n");
}
return 0;
}
//This is what I see when I input ‘William’
Hello, please enter your name: William
Searching…
Invalid user. Please enter first and last name.
Hello, please enter your name: Searching…
Invalid user. Please enter first and last name.
Hello, please enter your name:
Ive tried rearranging the text and am quite a noob in the coding space right now so I am actively trying to learn as I go. I believe the birthdate text may be backwards but my first priority is to see that text in the first place. Thank you in advance!
user25275170 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.