Question: C program Description This assignment is to write a program that will prompt the user to enter a negative integer. Your program should print a

 C program Description This assignment is to write a program that C program
will prompt the user to enter a negative integer. Your program should

Description This assignment is to write a program that will prompt the user to enter a negative integer. Your program should print a message indicating that the number must be negative if the user enters a positive number or zero and prompt them again. Your program should continue this behavior until you have received a negative integer. Use a loop to trap the user until you get the value that you want. You should also examine the return value of scanf to see if you were able to successfully read an integer at all and if not then you should attempt to clear the keyboard buffer by reading characters from the keyboard up to and including the new line (' ') or NULL character ('\0'). In fact, even if you successfully read a postive integer or zero, you should clear the buffer afterwards. Use the function that we wrote in class as below to clear the buffer in these cases. void clearKeyboardBuffer(void) { char ch; scanf("%c", &ch); while (ch != ' ' && ch != '\0') { scanf("%c", &ch); Run my program Stop > run Please enter a negative number: 100 I'm sorry, you must enter a negative integer less than zero: why? I'm sorry, you must enter a negative integer less than zero: argh! I'm sorry, you must enter a negative integer less than zero: 800 I'm sorry, you must enter a negative integer less than zero: -345 I got the number -345

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!