Answer to Question #37447 in C++ for Mohammed shabib

Question #37447
Consider a text file named “Data.txt” which contains an unknown number of positive integers. Write a C++ program which reads the numbers from the file and display their total and maximum on the screen. The program should stop when one or more of the conditions given below become true:
1. The total has exceeded 5555.
2. The end of file has been reached.
1
Expert's answer
2017-05-05T09:29:42-0400
#include <iostream> 
#include <fstream>

using namespace std;

int main(int argc, char const *argv[])
{
int total = 0,
max = 0;
ifstream input;
input.open ("Data.txt");
while ((!input.eof()) && (total < 5555))
{
int temp;
input >> temp;
total += temp;
if (temp > max)
max = temp;
}
input.close ();
cout << "Total: " << total << endl;
cout << "Maximum: " << max << endl;
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS