Assume has been included and the following variables have been declared in main():   Create code that would be a part of main() that do the following: Use a while loop to prompt the user to enter how many numbers will be entered and store this value in the howmany variable. Stay in the loop as long as the user enters a value that is less than or equal to zero. When the while loop is finished, use a for loop to do the following: Prompt the user to enter a number. You will need to declare a loop counter variable and it must be used in this prompt. Store this number in the num variable. If the number is negative, add 1 to the total variable. The howmany variable must be used in the condition for this loop. When the while loop is finished, display the number of negative numbers entered in a sentence.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Assume <iostream> has been included and the following variables have been declared in main():

 

Create code that would be a part of main() that do the following:

  • Use a while loop to prompt the user to enter how many numbers will be entered and store this value in the howmany variable. Stay in the loop as long as the user enters a value that is less than or equal to zero.
  • When the while loop is finished, use a for loop to do the following:
    • Prompt the user to enter a number. You will need to declare a loop counter variable and it must be used in this prompt.
    • Store this number in the num variable.
    • If the number is negative, add 1 to the total variable.
    • The howmany variable must be used in the condition for this loop.
  • When the while loop is finished, display the number of negative numbers entered in a sentence.

Here is a sample output:

 
 
 
How many numbers will there be? 0
Number must be positive. Try again.
How many numbers will there be? -1
Number must be positive. Try again.
How many numbers will there be? 4
Enter number #1: -22
Enter number #2: 88
Enter number #3: -66
Enter number #4: -77
You entered 3 negative numbers.
Transcribed Image Text:How many numbers will there be? 0 Number must be positive. Try again. How many numbers will there be? -1 Number must be positive. Try again. How many numbers will there be? 4 Enter number #1: -22 Enter number #2: 88 Enter number #3: -66 Enter number #4: -77 You entered 3 negative numbers.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education