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 pay the beggar on each day. The output of your program should appear as follows:
DayAmount Owed
--- ------------------
1 0.01
2 0.02
3 0.04
..
. .
. .
64 .
1
Expert's answer
2015-02-03T12:04:43-0500
#include <stdio.h> using namespace std; int main() { float amount = 0.005; printf("Day Amount Owed\n"); printf("--- -----------\n"); for (int i = 1; i <= 64; i++) { amount *= 2; printf("= %.2f\n", i, amount); } return 0; }
Comments
Leave a comment