65 698
Assignments Done
99,2%
Successfully Done
In October 2018

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.
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions