this is what code i have and i need help finishing thanks!!!
Write a program that demonstrates using an array to perform some simple statistics. Your program should declare a 10 element double array, use one loop to read 10 values from the user and store them in the array, use a second loop to compute the sum and average of the values in the array, use a third loop to find the largest and smallest values in the array.
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
int main(){
double myArray[10];
int sum=0;
double average;
//prompt user to input 10 values
cout<<"Enter 10 numbers please: \n";
for(int counter=0;counter<10;counter++){ //loop 10 times 0-9
cout<<"Enter number "<<counter+1<<": ";
cin>>myArray[counter]; //store value in the array
}//end loop for
cout<<endl;
for(int counter=0;counter<10;counter++){//loop 10 times 0-9
sum+=myArray[counter]; //compute the sum
}//end loop for
average=sum/10; //calculate the average
/*
Now you can write the third loop using the same logic
hint: think what should be the initial value of a smallest and largest
variable at the first loop
*/
cout<<"The sum is: "<<sum<<"\nThe average is: "<<average<<'\n'<<endl;
return 0; //indicates successful termination
}//end main
Enter 10 numbers please:
Enter number 1: 1
Enter number 2: 2
Enter number 3: 3
Enter number 4: 4
Enter number 5: 5
Enter number 6: 6
Enter number 7: 7
Enter number 8: 8
Enter number 9: 9
Enter number 10: 10
The sum is: 55
The average is: 5
int main()
{
double myArray[10];
double sum=0;
double average;
cout<<"Enter 10 numbers please: \n";
for(int counter=0;counter<10;counter++)
{
cout<<"Enter number "<<counter+1<<": ";
cin>>myArray[counter];
}
cout<<endl;
for(int counter=0;counter<10;counter++)
{
sum+=myArray[counter];
}
average=sum/10;
cout<<"The sum is: "<< sum <<"\nThe average is: "<<average<<'\n'<<endl;
int min, max,counter;
min=myArray[counter];
max=myArray[counter];
for(int counter=1;counter<10;counter++)
{
if(min>myArray[counter])
{
min=myArray[counter];
}
elseif(max<myArray[counter])
{
max = myArray[counter];
}
}
cout<<"Maximum number is: "<< max << endl;
cout<<"Minimum number is: "<< min << endl;
return 0;
}
In lines 30 and 31, you are attempting to use counter without having initialized it. However, you don't really need a counter variable there based on how your following for-loop works. min = myArray[0] and max = myArray[0] will probably work fine.
int min, max;
min = myArray[0];
max = myArray[0];
for(int counter=1;counter<10;counter++)
{
if(min>myArray[0])
{
min=myArray[0];
}
elseif(max<myArray[0])
{
max = myArray[0];
}
}
cout<<"Maximum number is: "<< max << endl;
cout<<"Minimum number is: "<< min << endl;
#include<iostream>
using std::cout;
using std::cin;
using std::endl;
#include<iomanip>
using std::setprecision;
int main(){
double myArray[10];
double average,
sum=0,
smallest,
largest;
//prompt user to input 10 values
cout<<"Enter 10 numbers please: \n";
for(int counter=0;counter<10;counter++){ //loop 10 times 0-9
cout<<"Enter number "<<counter+1<<": ";
cin>>myArray[counter]; //store value in the array
}//end loop for
cout<<endl;
for(int counter=0;counter<10;counter++){//loop 10 times 0-9
sum+=myArray[counter]; //compute the sum
}//end loop for
average=sum/10; //calculate the average
for(int counter=0;counter<10;counter++){
if(counter==0){ //if the first loop is executing
smallest=myArray[counter];
largest=myArray[counter];
}else{
if(myArray[counter]<smallest)
smallest=myArray[counter];
if(myArray[counter]>largest)
largest=myArray[counter];
}//end if...else
}//end loop for
cout<<"The sum is: "<<sum<<"\nThe average is: "<<setprecision(3)<<average
<<"\nThe smallest number is: "<<smallest<<"\nThe largest number is: "
<<largest<<'\n'<<endl;
return 0; //indicates successful termination
}//end main
Enter 10 numbers please:
Enter number 1: 1
Enter number 2: 2
Enter number 3: 3
Enter number 4: 4
Enter number 5: 5
Enter number 6: 6
Enter number 7: 7
Enter number 8: 8
Enter number 9: 123
Enter number 10: 90
The sum is: 249
The average is: 24.9
The smallest number is: 1
The largest number is: 123