Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use C programming 1.Input \'y\' or \'Y\' will quit program 2.Input \'\ \' will p

ID: 3789266 • Letter: U

Question

Use C programming 1.Input 'y' or 'Y' will quit program 2.Input ' ' will print nothing 3.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

//C Program

#include <stdio.h>

int main()
{

while (1)
{
   char ch;
printf("Would you like to exit ?(y/n) ");
    scanf("%c",&ch);
if((ch=='y')||(ch=='Y'))
{
    return 0;
   }
   else if(ch==' ')
   {
     
   }
  
  
}
return 0;
}

Output :

Would you like to exit ?(y/n)
g
Would you like to exit ?(y/n)

h
Would you like to exit ?(y/n)

h
Would you like to exit ?(y/n)

u
Would you like to exit ?(y/n)

g
Would you like to exit ?(y/n)

y

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote