Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An old Arabian legend has it that a fabulously wealthy but unthinking king agree

ID: 3639690 • Letter: A

Question

An old Arabian legend has it that a fabulously wealthy but unthinking king agreed to give a beggar one cent and double the amount for 64 days. Using this information, write, run, and test a C++ program that displays how much the king must bay the beggar on each day. The output of your program should appear as follows.

Also, add an if statement to find out on which day the king will have paid the beggar a TOTAL of one million dollars. (Note, not the exact perfect amount, just to the nearest day) Report this day at the end of the loop. Remember to use Input output manipulation (setw, fixed, setprecision, etc) to make the format look good. For example, setw(20) << fixed << setprecision(2) …

Write the C++ code for this problem.

I know it is suppose to look something like this:

Day Amount Owed
--- -----------
1 0.01
2 0.02
3 0.04
. .
. .
. .
64 .





I cannot seem to get what the program is asking i am only able to get the grand sum, but i cannot get the amount owed a day at a time.




I actually did this im not just trying to get the entire problem but its comming out wrong, heres what i have:







#include













< iostream >








#include













< iomanip >








#include













< math.h >








using









namespace

std;







void









main(void

)

{










int

day = 1;








const int

max =64;

cout.setf(ios::fixed);



cout.setf(ios::showpoint);



cout.precision(2);



cout <<endl;



cout <<






"An Old Arabian Legend "

<<endl;

cout << setw(5) <<






"Day" << setw(25) << "Amount Owed"

<< endl;

cout << setw(5) <<






"---" << setw(25) << "-----------"

<< endl;

cout << endl;










float

grand_total = 0.0, day_total = 0.0;








for

(day = 1; day <= max; day++);

{



day_total = pow(2.0,day-1)/100;



cout << setw(5) << day << setw(22) << day_total;



cout << endl;



grand_total = grand_total + day_total;



}



cout << endl;



cout <<






"The King paid the beggar a grand sum of $ " << grand_total <<"!"

<< endl;

system(






"pause"

);








return

;

}











Help please!








Explanation / Answer

#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
   const int MAX = 64;
   int day = 1;
   double dayTotal = 0.0;
   double grandTotal = 0.0;
   int>
   cout << "An Old Arabian Legend " << endl << endl;

   cout << setw(5) << "Day"
        << setw(25) << "Amount Owed" << endl;
   cout << setw(5) << "---"
        << setw(25) << "-----------" << endl;

   for (day = 1; day <= MAX; day++)
   {
      dayTotal = pow(2.0, day - 1) / 100.0;
      cout << setw(5) << day
           << setw(25) << fixed << setprecision(2) << dayTotal;
      grandTotal += dayTotal;
      if (grandTotal >= 1000000.0 && !oneMillionDay)
      {
        >       }
      cout << endl;
   }

   cout << endl;
   cout << "The King paid the beggar a total of one million dollars on day "
        << oneMillionDay << endl << endl;
   cout << "The King paid the beggar a grand sum of $"
        << grandTotal << "!" << endl;
   

   cin.get();
   return 0;
}