#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;
}
в основном последний для цикла не распечатывает сумму правильно. Это дает некоторые странные десятичные знаки. Был попыткой увидеть wheres ошибки, но im только новичок в C++, и я не очень умный в информатике. Любая помощь будет оценена!Сумма не будет корректно напечатана в этом типе массива
Бог благословит вашу душу Эмиля !!!!! – Chang