1 Prompt the user to enter five numbers being five peoples w

(1) Prompt the user to enter five numbers, being five people\'s weights. Store the numbers in a vector of doubles. Output the vector\'s numbers on one line, each number followed by one space. (2 pts) Ex: Enter weight 1 236.0 Enter weight 2 89.5 Enter weight 3 142.0 Enter weight 4 166.3 Enter weight 5 93.0 You entered 236 89.5 142 166.3 93 (2) Also output the total weight, by summing the vector\'s elements. (1 pt) (3) Also output the average of the vector\'s elements. (1 pt) (4) so output the max vector element. (2 pts)

Solution

Source code:

#include<iostream>
using namespace std;

int main()
{
double weight[5],avg=0,total=0,max=0;
int i;
for(i=0;i<5;i++)
{
cout<<\"\ Enter weight\"<<i+1<<\":\"<< endl;
cin>>weight[i];
}
cout<<\"\ You entered:\" ;
for(i=0;i<5;i++)
{
cout<< weight[i];
}
  
for(i=0;i<5;i++)
{
total=total+weight[i];
}
cout<<\"\ Total weight:\" << total;
avg=total/5;
cout<<\"\ Average weight:\" << avg;
for(i=0;i<5;i++)
{
if(weight[i]>max)
{
max=weight[i];
}
}
cout<<\"\ Maximum weight:\" << max;
return 0;
}

 (1) Prompt the user to enter five numbers, being five people\'s weights. Store the numbers in a vector of doubles. Output the vector\'s numbers on one line, ea

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site