int main() {
double sum = 0;
int x;
int count = 1;
double avg;
int min = 2;
int max = 7;
double nocmin = 9;
double nocmax = 6;
double median = 8;
ifstream myFile("V:\\Downloads\\random.txt");
if (!myFile) {
cout << "Unable to open file" << endl;
}
while (myFile >> x) {
sum = sum + x;
count = count + 1;
avg = sum / count;
if (x > max) {
max = x;
}
if (x < min) {
min = x;
}
}
for (int x = 0; x <= count; x++) {
if (x = min) {
count++;
}
}
cout << "Count: " << count << endl;
cout << "Sum: " << sum << endl;
cout << "Average: " << avg << endl;
cout << "Minimum: " << min << endl;
cout << "Number of Occurances of Minimum: " << nocmin << endl;
cout << "Maximum: " << max << endl;
cout << "Number of Occurances of Maximum: " << nocmax << endl;
if you read the file into a data structure you can use a pair of count_if(...) statements
or you can just add logic where you find the min and max:
is current element == to min? mincount ++;
is current element new min? min = current, mincount = 0;
and same idea for max.
unrelated but computing average inside the loop is not useful, it is a "once at the end" calculation. Mostly harmless, but burns the cpu to compute then discard values.