Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed C program
image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions

Question

What is digital literacy? Why is it necessary?

Answered: 1 week ago