Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ One-dimensional Array Write a program that lets the user enter 10 values int

ID: 3759748 • Letter: C

Question

C++ One-dimensional Array Write a program that lets the user enter 10 values into an array. The program should then display the largest, the smallest, the sum, and the average values. The program output should be as shown below: The values are as following: The smallest value is: ??? The highest value is: ??? The sum is: ??? The average is: ???

This is what i have started with

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
   // open my file
   outfile.open("C: \documents\afile.dat");
   system("pause");
   return 0;
}

can you please show me that it works and run

Explanation / Answer

int main()
{
int maxnum = 0,minnum = 101,number,sum = 0;
int count = 0;
float average;
int SENTINEL = -1;

while(number != SENTINEL)
{
cout <<"Enter a number(-1 to quit): ";
cin >> number;

if (number > maxnum && number < 101)
maxnum = number;

else if (number <= maxnum && number !=SENTINEL)
minnum = number;

  
sum = sum+number;
count++;   
}

count--;


average=(float)sum/(float)count;


cout<<" You entered " << count << " numbers."<<endl
<<"Their average is : " <<setw(3) << fixed << setprecision(2) << showpoint<<average<<endl
<<"Max number is : "<<maxnum<<endl
<<"Min number is : "<<minnum << endl;

return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote