Suppose that a text file text.txt contains an unspecified number of scores. Write a program that reads the scores from the file and displays their total and average. Scores are separated by blanks.
What will be an ideal response?
```
#include
#include
using namespace std;
int main()
{
ifstream input;
// Open a file
input.open("Exercise13_1.txt");
if (input.fail())
{
cout << "File does not exist" << endl;
cout << "Exit program" << endl;
return 0;
}
int number = 0;
int total = 0;
while (!input.eof()) // Continue if not end of file
{
input >> number;
total += number;
}
input.close();
cout << "total is " << total << endl;
return 0;
}
```
You might also like to view...
Methods that call themselves are known as ________ methods.
a) reiterative b) self-calling c) repeat-calling d) recursive
Answer the following questions true (T) or false (F)
1. You can not place a try block and its following catch blocks inside a larger try block or inside a larger catch block. 2. The finally block contains code to be executed whether or not an exception is thrown in a try block.