The program uses an array to store the amount of money a game show contestant wo
ID: 3804025 • Letter: T
Question
The program uses an array to store the amount of money a game show contestant won in each of five days. The program should display the total amount won and the average daily amount won. It should also display the day number (1 through 5) corresponding to the highest amount won. Complete the program. Save and then run the program. in c++
#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
void getTotal();
double getAvg();
int getHighDay();
int main()
{
int winnings[5] = {12500, 9000, 2400, 15600, 5400};
int total = 0;
double average = 0.0;
int highDay = 0;
cout << fixed << setprecision(2);
cout << "Total amount won: $" << total << endl;
cout << "Average daily amount won: $" << average << endl;
cout << "The contestant's highest amount won was on day "
<< highDay << "." << endl;
return 0;
} //end of main function
//*****function definitions*****
void getTotal()
{
} //end of getTotal function
double getAvg()
{
} //end of getAvg function
int getHighDay()
{
} //end of getHighDay function
Explanation / Answer
#include <iostream>
#include<conio.h>
#include <iomanip>
using namespace std;
//function prototypes
int getTotal(int []);
double getAvg(int []);
int getHighDay(int []);
int main()
{
int winnings[5] = {12500, 9000, 2400, 15600, 5400};
int total = 0;
double average = 0.0;
int highDay = 0;
cout << fixed << setprecision(2);
total=getTotal(winnings);
cout << "Total amount won: $" << total << endl;
average=getAvg(winnings);
cout << "Average daily amount won: $" << average << endl;
highDay=getHighDay(winnings);
cout << "The contestant's highest amount won was on day "
<< highDay << "." << endl;
getch();
return 0;
} //end of main function
//*****function definitions*****
int getTotal(int winnings[5])
{
int i,s=0;
for(i=0;i<5;i++)
s=s+winnings[i];
return s;
} //end of getTotal function
double getAvg(int winnings[5])
{
int i,s=0;
double avg;
for(i=0;i<5;i++)
s=s+winnings[i];
avg=double(s)/5.0;
return avg;
} //end of getAvg function
int getHighDay(int winnings[5])
{
int i,high_day=0,max=0;
max=winnings[0];
for(i=1;i<5;i++)
{
if(max<winnings[i])
high_day=i+1;
}
return high_day;
} //end of getHighDay function
Sample Output :
Total amount won: $44900
Average daily amount won: $8980.00
The contestant's highest amount won was on day 4.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.