Question
There is a problem in my textbook that I just can't get theright solution for. It says: Write a looping code segment that takes as input up to 20integer scores from file indata, and outputs theiraverage. If the file contains fewer than 20 scores, the segmentshould still output the correct average. If the file contains morethan 20 scores, the additional numbers should be ignored. Be sureto consider what happens if the file is empty. There is a problem in my textbook that I just can't get theright solution for. It says: Write a looping code segment that takes as input up to 20integer scores from file indata, and outputs theiraverage. If the file contains fewer than 20 scores, the segmentshould still output the correct average. If the file contains morethan 20 scores, the additional numbers should be ignored. Be sureto consider what happens if the file is empty.
Explanation / Answer
please rate - thanks #include #include using namespace std; int main() {int a,sum=0,i=0; ifstream in; ofstream out; in.open("indata.txt"); if(in.fail()) { cout