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
1
Expert's answer
2012-10-26T11:31:58-0400
#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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS