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"; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment