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


1. 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 IOOP1 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 LOOP 3 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 When the user enters n, then the Do you want to do all of this again? y program continues on to Part #5. Enter a file name to read from: in. in Test this!!! LOOR3 total =18.0000 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 Input/Output Example You must create vour own input files so you can determine correct output. For these tests, I only use files with 5 or 7 numbers in them. Your output should look like this: (Please copy and paste the output text AND prompts into your code! I match on this text to grade your programs. Use fixed and setprecision(4).) Enter the number to add the even numbers up to: 33 LOOP1 total =272 Enter a lower and upper number to sum: 7779 LOOP2 total =234 Enter a file name to read from: inl.in LOOP 3 total =18.0000 Do you want to do all of this again? Y Enter a file name to read from: in2. in LOOP3 total =14.0000 Do you want to do all of this again? y Enter a file name to read from: in2.in LOOP3 total =14.0000 Do you want to do all of this again? n Enter another file name to add 5 numbers from: in 1 . in second number =1.0000 LOOP4 total =18.0000 End of Program
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
