Hello vmansuria,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
I do not know if you are stuck using "float", but the preferred floating point type these days is a "double".
You have a few problems in your code that I have noted with comments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
// <--- needs header files.
int main()
{
constexpr size_t MAXSIZE{ 100 }; // <---Added
double sum = 0.0, average{}; // <--- Changed.
double numbers[MAXSIZE]{}; // <--- Changed. Type and array size
int numEnter = 0;
double max = 0.0, min = 10.0; // <--- Changed.
while (numEnter < 100)
{
cout << "Please enter the sale amount: ";
double num;
cin >> num;
// <--- Need if statement to check for -1. If true break out of while loop.
while (num < 1) // <--- Changed. A valid entry is anything greater than zero.
{
cout << "Invalid amount, try again.\n";
cout << "Please enter the sale amount: ";
cin >> num;
}
numbers[numEnter++] = num;
}
}
|
Once you have your array filled the variable "numEnter" will let you know how much of the array is used.
If you have learned about functions they would be useful for the min, max and mean if not you can just add to your code after line 25.
Other than using a vector there is no unlimited array. If you fill your fixed array then you will have to create a dynamic array larger and copy the old array to the new array. I have not used a dynamic array in this context, so someone else may have more insight.
You have a good start with a few changes and additions.
Hope that helps,
Andy