Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Using the variables shown below and a flag-controlled loop write a set of C++ statements that accumulate the values read from the file in

C++

Using the variables shown below and a flag-controlled loop write a set of C++ statements that accumulate the values read from the file in total as long as total does not get greater than max.

For example, if the content of the input file is: 10 25 17 6 24 23 12 5

For max = 100, the value in total should be 82 (10+25+17+6+24)

For max = 75, the value in total should be 58 (10+25+17+6)

Assume that max will never make your loop to read beyond the end of the file and the values in the file are all valid. Implement the loop using a while statement.

Initialize variables according to your needs. Display the value of total.

ifstream myInfile;

myInfile.open("input.txt");

int value; // value read from file

int total;

bool flag;

int max = 100;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

4th Edition

0805360476, 978-0805360479

More Books

Students also viewed these Databases questions

Question

Reach consensus on one or two of the major causes of the problem.

Answered: 1 week ago