65 746
Assignments Done
99,3%
Successfully Done
In October 2018

# Answer to Question #64391 in C++ for yashfa

Question #64391
A fabulously wealthy but unthinking king agreed to give a beggar one cent and double the amount for 64 days in c++ by while loop.
#include <iostream>
#include <vector>

int main()
{
int counter = 0;
std::vector<int> amount_of_money;
amount_of_money.push_back(1);
int buff = 0;
while (counter < 64) {
for (int i = 0; i < amount_of_money.size(); i++) {
amount_of_money[i] = amount_of_money[i] * 2 + buff;
if (amount_of_money[i] / 10 > 0) {
buff = amount_of_money[i] / 10;
amount_of_money[i] %= 10;
if (i + 1 == amount_of_money.size()) amount_of_money.resize(i + 2);
}
else buff = 0;
}
counter++;
}
std::cout << "After 64 days the beggar will have ";
for (int i = amount_of_money.size() - 1; i >= 0; i--)
std::cout << amount_of_money[i];
std::cout << " cents.\n\n";
system("pause");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!