I always give a positive rating! Language is C++ I know this looks really long, but this is actually pretty easy. Just f

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

I always give a positive rating! Language is C++ I know this looks really long, but this is actually pretty easy. Just f

Post by answerhappygod »

I always give a positive rating!
Language is C++
I know this looks really long, but this is actually
pretty easy.
Just follow the steps in the document below and paste
your code in the answer.
Thanks!
I Always Give A Positive Rating Language Is C I Know This Looks Really Long But This Is Actually Pretty Easy Just F 1
I Always Give A Positive Rating Language Is C I Know This Looks Really Long But This Is Actually Pretty Easy Just F 1 (128.52 KiB) Viewed 68 times
In Class 6 - Lots 'o while Loops In this assignment, you write a C++ program in which you write several while loops that perform actions like adding up numbers and opening files to read from! Goals Practice with • writing lots of while loops Problem Statement You are writing several individual while loops for this assignment. The 4th loop is a "Do you want to do that again?" type of loop around the loop for Part 3. Follow the instructions below. 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 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: 22 44 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 When the user enters n. then the LOOP3 total = 18.0000 program continues on to Part 5 Do you want to do all of this again? Y Enter a file name to read from: in.in v Test this!!! LOOP3 total = 18.0000 Do you want to do all of this again? y 36 here would be wrong! Enter a file name to read from: in error opening file! Error message when the file docs not open (does not exist). 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 your 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: 77 79 LOOP2 total = 234 Enter a file name to read from: inl.in LOOP3 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: ini.in second number = -1.0000 LOOP4 total = 18.0000 End of Program! The following shows what happens when the input file does not exist: (You should use a break; statement instead of using "return 1;" inside the if statement for when the file does not open so that the program continues on to the next step in the assignment.) Enter the number to add the even numbers up to: 6

1 3 LOOP1 total = 12 Enter a lower and upper number to sum: LOOP2 total = 6 Enter a file name to read from: in.in error opening file! Enter another file name to add 5 numbers from: inl.in second number = -1.0000 LOOP4 total = 18.0000 End of Program! Submit Your Work To submit your work to Web-CAT to be graded. Outline main() { // variables // #1 while( ) t } // #2 while() [ } while() // #4 // #3 while) 1 } } while() // #5 & 6 }
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply