I'm trying to create a program which takes in different memory sizes for an unknown number of files and:
(1) counts how many files there are
(2) the total memory used
(3) calculates the average size of these files.
I've tried my best with it and although the program works, the values for the second and third questions comes up as 0, so therefore doesn't work. I would appreciate any help and TIA! :)
#include <iostream>
usingnamespace std;
int main(int argc, constchar * argv[])
{
int fileSize[100];
int count=0-1;
// Asks user to enter file size value and repeats until user enters 0 to stop
do {
cout << "Please enter the file size. Enter 0 once all files have been entered to proceed.\n";
cin >> fileSize[100];
count++; // Counts the number of user inputs
} while (fileSize[100] != 0);
int memoryUsage=0;
// Calculates the sum of the users input to display total memory usage
for (int i=0; i<count; i++)
{
memoryUsage+=fileSize[i];
}
int average;
// Calculates the average size by dividing the memory usage by the number of user inputs and assigs this value to the variable named average
average = memoryUsage/count;
cout << "There are " << count << " files.\n"; // Displays the number of files there are to the user
cout << "The total memory used is " << memoryUsage << " MB.\n"; // Displays the total memory used to user
cout << "The average memory size of these files is " << average << ".\n"; // Displays the average of the memory files sizes to user
cin.get();
return 0;
}