Question: 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

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 do 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;

Must be in C++

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!