146k views
3 votes
AP CSA help needed. Java please.

A child’s parents promised to give the child $10 on her twelfth birthday and double the gift on every subsequent birthday until the gift exceeded $1000. Write a Java program to determine how old the girl will be when the last amount is given, and the total amount she received including the last gift.

Thank you!

1 Answer

2 votes
#include using namespace std;int main(){int year = 12,value = 10,total = 0;do{year++;value *= 2;total += value;}while(value*2 < 1000);cout << "Age: " << year << endl;cout << "Last gift: " << value << endl;cout << "Total: " << total << endl;cin.get();return 0;
User Khoa Le
by
4.0k points