Question: This assignment is to write a program that will prompt the user to enter a negative integer. Write a function called getNegint that takes no

 This assignment is to write a program that will prompt theuser to enter a negative integer. Write a function called getNegint that

This assignment is to write a program that will prompt the user to enter a negative integer. Write a function called getNegint that takes no parameters and returns an integer. Your program will call this function once and then output the result. This getNegInt function should display a message asking the user to enter a negative integer and then return the number that they enter. If the user enters a positive integer or zero, the function should continue prompting the user until you receive 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 positive 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 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!