So I have an array program that needs looking over and if ne

So I have an array program that needs looking over and if needed changed up a bit. The program stores the amount of money a game show contestant won in each of the five days. the program should display the total amount won and the daily average amount won. it shouild also display the day number (1 to 5) corresponding to the highest amount won.

Here\'s the program

#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

Solution

#include <iostream>
#include <iomanip>
using namespace std;
//function prototypes
int getTotal();
double getAvg();
int getHighDay();
int winnings[5] = {12500, 9000, 2400, 15600, 5400};

int main()
{

int total = getTotal();
double average = getAvg();
int highDay = getHighDay();

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*****
int getTotal()
{
int total=0;
for(int i=0; i<5; i++)
total+=winnings[i];
} //end of getTotal function
double getAvg()
{
return getTotal()/5.0d;
} //end of getAvg function
int getHighDay()
{
int maxVal=winnings[0],maxIndex=0;
for(int i=1; i<5; i++)
if(maxVal<winnings[i])
{
maxVal=winnings[i];
maxIndex=i;
}
return maxIndex;
} //end of getHighDay function

OUTPUT:

Total amount won: $5376

Average daily amount won: $1075.20
The contestant\'s highest amount won was on day 3.


Press any key to continue.

So I have an array program that needs looking over and if needed changed up a bit. The program stores the amount of money a game show contestant won in each of
So I have an array program that needs looking over and if needed changed up a bit. The program stores the amount of money a game show contestant won in each of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site