An old Arabian legend has it that a fabulously wealthy but unthinking king agree
ID: 3639626 • 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 pseudocode for this problem.
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 .
Explanation / Answer
please rate - thanks
#include <iostream>
#include <iomanip>
using namespace std;
main()
{int i,day=-1;
double owed=.01,total=0;
cout<<"Day Amount Owed ";
cout<<"--- --------------------- ";
for(i=1;i<=64;i++)
{total+=owed;
if(day==-1)
if(total>1000000)
day=i;
cout<<setw(2)<<left<<i<<setw(25)<<right<<setprecision(2)<<fixed<<owed<<endl;
owed*=2;
}
cout<<"The day would have paid a Total of just over $1,000,000 on day "<<day<<endl;
system("pause");
return 0;
}