Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started