Flexible Count-controlled while
Loop
Exercise:
Create a C++ program ex1_count.cpp
wih the the following code in the Visual Studio project or copy the following code into your IDE:
When it is complete, this program will allow the user to add together any
number of integers. It will use a while
with two variable - one for the loop counter, and one for the total number
of loop repetition. The user first types how many numbers they wish to add,
then types the numbers one at a time pressing enter after each one.
Instructions:
- Read the code carefully, paying attention to the comments.
- Complete the program by adding one line of code after every "Add code: " comment.
-
Compile and run the program. Use the the following input values to test
your program:
loop total: 5
five numbers to be added 3, -2, 0, 9, 1. - Your output should look like this:
Please input the number of integers that you would like to add: 5 Enter an integer value: 3 Enter an integer value: -2 Enter an integer value: 0 Enter an integer value: 9 Enter an integer value: 1 The sum of the 5 integers is 11
- If that worked, test design a second test for your program with 3 or 4 input integers of your choice.
When you are done:
- Take a screenshot of your IDE and console window after compiling the code and then running the program twice:
- with the test data above
- with your own test data
- For this exercise, you will have:
ex1_count.cpp
. - Complete all the exercises in this lab and upload the .cpp files and screenshots to URCourses.