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 in said file. This is my code thus far and my problem/question is how do you distinguish +- numbers from +- numbers that have a decimal, ie real numbers from integers.
#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 2;
}
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;
}