Well here's what I got. I need help to be able to use negative numbers and also it keeps giving me the average and sum for all 10 numbers but I want it to do that for all the numbers combined.
#include <iostream>
#include <cmath>
usingnamespace std;
constint SIZE = 10;
int main()
{
double myArray[SIZE];
for (int i=0; i<10; i++)
{
cout << "Enter a valid number: " << endl;
cin >> myArray[i];
}
for (unsignedint i=0;i<10; i++)
{
int sum = 0;
sum += myArray[i];
double avg = sum/10;
cout<<"The sum is: "<<sum<<endl;
cout<<"The average is: "<<avg<<endl;
}
double smallest = 99999999;
double largest = 0;
for (size_t i = 0; i != SIZE; ++i)
{
if (myArray[i] <= smallest)
smallest = myArray[i];
if (myArray[i] >= largest)
largest = myArray[i];
cout<<"The smallest is: "<<smallest<<endl;
cout<<"The largest is: "<<largest<<endl;
}
return 0;
}
If I have correctly understood you need the following
1 2 3 4 5 6 7 8 9 10
double sum = 0;
for (unsignedint i=0;i<10; i++)
{
sum += myArray[i];
}
double avg = sum/10;
cout<<"The sum is: "<<sum<<endl;
cout<<"The average is: "<<avg<<endl;
That helped just a little. But there's something wrong with the smallest/largest part and it keeps giving me the smallest and largest for every single number