60 664
Assignments Done
97,7%
Successfully Done
In April 2018

Answer to Question #17015 in C++ for zheer

Question #17015
Write a .cpp program that prompts the user for 5 prices. You are to store the values in an array. Once the user has entered all of the prices, you should:

Write a function that calculates the sum of all the prices and returns control to the main function for display
Write a function that calculates the average of all the prices and returns control to the main function for display
Write a function that calculates and displays prices that are higher than the average
Expert's answer
#include<iostream>
using namespace std;

float p[5];
int i;

float sum(){
int sum=0;
for (i=0;i<5;i++) sum+=p[i];
return sum;
}

float ave(){
return sum()/5;
}

void high(){
int a = ave();
for (i=0; i<5; i++)
& if (p[i] > a) cout<<p[i]<<" ";
}

void main(){
for (i=0; i<5; i++){
& cout<<"enter a price: ";
& cin>>p[i];
}
cout<<"sum: "<<sum()<<"\naverage: "<<ave()<<"\nhigher than the average: ";
high();
cout<<"\n";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions