I need help in reading a text file and by using a switch statement the user can either press 1 to find the average of all the integers in the text file, and by pressing 2 they find only the averages of the real numbers (only positive integers) in said file. I need help on the second part in computing the average for the real numbers only. This is my code thus far
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int n;
double average(0), sum(0), count(0);
ifstream data;
data.open("data.txt");
if(data.fail( ))
{
cout << "Error Opening File"<<endl;
return 1;
}
while(!data.eof())
{
data>>n;
sum=sum+n;
count++;
}
int rank;
cin >> rank;
switch(rank){
case 1:
average=(sum)/(count);
cout << "The Average Is: " << average << endl;
break;
}
data.close();
cout << endl;
system("PAUSE");
return 0;
}