335,473 views
25 votes
25 votes
Your grandma gave you $100 when you were born. On your 1st birthday, she gives you $105. Your 2nd birthday, she gives you $110. Every birthday, she gives you $5 more than your last. Write a program which simulates this using a for loop and an accumulator. Ask the user how old they're turning and calculate how much they will receive this year as well as the total amount of money they have ever received from grandma.

EXAMPLE: On your 5th birthday, you will receive $125. Over your whole life, you will have received $675.

User Greenoldman
by
2.3k points

1 Answer

12 votes
12 votes

Answer:

#include <stdio.h>

int main(){

int total_amount = 100;

int age, i, amount;

printf("How old are you?: ");

scanf("%d", &age);

//int amount = 100 + (age * )

for (i = 1; i <= age; i ++){

amount = 100 + 5 * i;

total_amount += amount;

}

printf("On your %dth birthday you will receive $%d\\\\", age, amount);

printf("Over your whole life you will have received $%d\\", total_amount);

return 0;

}

Step-by-step explanation:

We start with initial value for total_amount = 100 since at age 0, the total_amount = 100

User VoidDweller
by
3.0k points