Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage 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 a new line (1n') or NULL character (10'). 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 clear_keyboard_buffer(void) char ch; scanf ("%c", &ch) while (ch'n' && ch!'10) scanf("c", &ch); Once you have a negative integer simply print it on the screen as shown below in zyBooks, under interactive terminal in develop mode: Predefine program input (optional) If you'd like to predefine your inputs, provide them here. 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 zeroi 800 I'm sorry, you must enter a negative integer less than zero: 345 I got the number-3451

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

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions