Use C programming input y or Y will quit input \ will print nothing Other input
ID: 3789236 • Letter: U
Question
Use C programming input y or Y will quit input will print nothing Other input will print the prompt again Q4) Write a program that exits when the user inputs the character 'y At the start of the program, prompt the user to input a character by printing the string "would you like to exit? (y/n)In". If the input character is 'y' or 'Y', then the program quits; if the input character is a newline, i.e 'In', then do not print anything; otherwise, print the prompt again. Note: In this program, you must use printf, scanf, and a while loop. You must name your file while c.Explanation / Answer
#include <stdio.h>
int main(void) {
printf("Would you like to exit? (y/n) ");
char c;
scanf("%c", &c);
//while loop to check for y or Y
while(c!='y' && c!='Y') {
//for a new line do not print prompt.
if(c != ' ')
printf("Would you like to exit? (y/n) ");
//scan next character in every case
scanf("%c", &c);
}
return 0;
}
Sample Input :
nN
qwy
Sample Output :
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.