applying a rule in c++

The payments will start in the amount of 1 dollar.

Rule A - Double the installment amount.
Rule B - Triple the installment amount.
You are free to apply Rule A every month, but Rule B can be applied only every other month.

I must maximize payments.

1st month's payment 1 dollar.
2nd month's payment 2 dollars. (doubled the amount)
3rd month's payment 6 dollars. (triple it every other months)
4th month's payment 12 dollars. (double the amount)
5th month's payment 36 dollars. (triple it every other month)
6th month's payment 72 dollars. (double the amount)
7th month's payment 216 dollars. (triple it every other month)
and so on ...
So a program that will compute the monthly payment amounts you will get over a given number of months.

Your program should take the number of months from user and create a loop to compute the payments for each month and output on screen.

So far I have
cout << "Here are your monthly installment amounts: " << endl;

for (int i = 0; i < 12; i++)
{
int m;
cout << "Month " << (i + 1) << ": ";

}

I need help to figure out how to create the rule have the numbers post correctly without cin it must be calculated. it is like a for loop.
Last edited on
Think for a second. If you were using std::cin, what would you do with the input? You would put it into a variable. So here you can just skip the input part and hard-code the initial variable amount.
int currenPaymt = 1;

Now, what do you do every month. In the first month you are supposed to print out the value "1", so you must be printing out the value before you apply a rule to it.

Next you need to determine which rule to apply. In even-numbered months (every other month) you apply rule B, otherwise apply rule A. So, how do you determine if the month is an even or odd month? (hint: read about the % operator.)

You'll have this running in no time.
thanks! So far this is what I have but I am having trouble I know my payment variable is not right since the outputs just spit 1 i am not sure how to make them double or triple since the first month must be 1

	int month;
	cout << "For how many months did they say you will recieve payments? "; 
	cin >> month;
	
	cout << endl;
	cout << "Here are your monthly installment amounts: " << endl;

	for (int i = 0; i < 13; i++)
	{
			int Month;
			int payment = 1; 
			cout << "Month " << i << ":       " << payment << endl;
			
			if (i % 2 == 0) 
			{ payment = payment * 2; }
				
			else { payment = payment * 3; }
	}

You are declaring payment inside the loop, so every time you go through the loop it resets to 1. Declare it before the loop and it will keeps it value from one iteration to the next.
Topic archived. No new replies allowed.