Hey guys. Quick question: How can I edit the getScores function to get it to stop when there are no more values in the data.txt file??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
#include <fstream>
using namespace std;
int getScores(int arr[]);
const int NUM = 100;
int main() {
int score[NUM];
int total;
total = getScores(score);
cout << total;
return 0;
}
int getScores(int arr[])
{
ifstream infile;
infile.open("/Users/jacobgallipeau/Documents/data.txt");
int test;
int end = 100;
int total = 0;
for(int i=0;i<end;i++)
{
infile >> test;
if(test > 0)
{
cout << test << endl;
arr[i] = test;
total++;
}
else{
total = end;
}
}
infile.close();
return end;
}
|
Last edited on
Last edited on