Hi everyone. I'm new to coding, just learning C.
I have three seperate codes I want to use and put together as one code:
1st:
Code:
{
char firstName[255];
char lastName[255];
printf("Enter your First Name: ");
scanf("%s", firstName);
printf("Enter your Last Name: ");
scanf("%s", lastName);
printf("Hello, %s %s!\n", firstName, lastName);
}
2nd:
Code:
{
char favColor[20];
printf("Hello, firstname, What is your favorite color? ");
gets(favColor);
printf("\nThanks, Buddy! Now I know that your favorite color is %s\n", favColor);
printf("\n");
}
3rd:
Code:
{
bool stayAlive = true;
char* userPrompt = "Do you want to exit this program (Y/N)? ";
char c;
printf("%s", userPrompt);
while(stayAlive)
{
c = getchar();
if(c == '\n')
continue;
else if(c == 'Y' || c == 'y')
stayAlive = false;
else
printf("%s", userPrompt);
}
puts("\n\nHave a nice day, Buddy!");
return 0;
}
I want to have all of these into one code for this program to work. The basics on what I want is:
- Person enters their name (Code 1)
- Gives a Greeting (Code 1)
- Welcomes the persons name, and asks their fav. color. (Code 2)
- Program tells them their fav. color. (Code 2)
- After those are done, program asks if person wants to leave. (Code 3)
All in that order. I was wondering if someone could help put this all together.
It all words excepte code 2. It prints the code, but doesnt allow the user to enter any info.
Thanks!