Question: Write a small piece of code that prompts the user for a number and adds up the even numbers from 1 to that entered number

Write a small piece of code that prompts the user for a number and adds up the even
numbers from 1 to that entered number using a while loop. You may not use for loops
for this assignment.
Enter the number to add the even numbers up to: 33
LOOP1 total =272
2. Write another small piece of code that prompts the user for 2 numbers and adds up the
numbers between (and including) the numbers using a while loop. You may not use
for loops for this assignment. Add all the numbers, not just the even or odd ones.
Enter a lower and upper number to sum: 2244
LOOP2 total =759
3. Write another small piece of code that prompts the user for a file name and adds up all of
the numbers in the file using a while loop. Read until EOF (end of file).
Enter a file name to read from: in.in
LOOP3 total =18.0000
4. Write another while loop around the code for #3 that prompts the user whether she or he
wants to prompt and read another file.
Enter a file name to read from: in.in
LOOP3 total =18.0000
Do you want to do all of this again? y
Enter a file name to read from: in.in
LOOP3 total =18.0000
Do you want to do all of this again? y
Enter a file name to read from: in
error opening file!
5. Write another while loop that prompts the user for file name and reads & adds up the first
5 numbers in the file. (Part 5 executes even when the error message is printed in Part4.
For Part 4, you should use a break statement inside the if, instead of doing a return
when the file doesn't open.)
Enter another file name to add 5 numbers from: in.in
LOOP4 total =18.0000
6. Finally, add to Part #5 a while loop to print the 2nd number in the file.
Enter another file name to add 5 numbers from: in.in
second number =-1.0000
LOOP4 total =18.0000

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!