#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
int sum;
double average;
int apple[50];
int b1;
int i;
outFile.open("apple_trip.txt");
for (i = 0; i < 50; i++)
{
b1 = rand() % 100;
outFile << b1 << endl;
}
outFile.close();
inFile.open("apple_trip.txt");
for (i = 0; i < 50; i++) // This loop ensures you don't keep overwriting
// the same value, which would be off by 1
{
inFile >> apple[i];
}
for (i = 0; i < 50; i++) // The loop variable is i, not apple[i], and we stop at 50
{
if (apple[i] < 25)
{
cout << apple[i] << " people picked less than 25 apples" << endl;
}
}
for (i = 0; i < 50; i++)
{
if (apple[i] > 80 && apple[i] < 100) // change < to >
{
cout << "The number of apples that is between 80 and 100 is : " << apple[i] << endl;
}
}
for (i = 0; i < 50; i++)
{
sum = 0;
sum += apple[i];
average = sum / 50.0;
cout << average;
}
return 0;
}
basically the last for loop wont print out the sum correctly. It gives some weird decimals thingy. Been trying to see wheres the error but im just a beginner in c++ and im not really smart in computer science. Any help will be appreciated!