So I am a bit confused on why the "total_Fees" does not increment. I thought if you only use the variable "i" it increments because that's how it works. I changed my code to this, and while it's the same and correct output, I don't know why we are using "
membership_Fee" =membership_Fee + (membership_Fee * .04);. How come the total_Fees does not work and the total_Fees does?
Also, another additional question, does the place where the line goes "membership_Fee" matters? I included comments on what I am talking about in the second pieace of code. I would imagine it does, because:
Loop starts, says Year 1: Costs: 2600 (because of the localized variable). Then calculates membership_Fee variable and does the calculation and store it in the membership_Fee variable, and runs the loop again and then the second loop starts saying Year 2: Cost: 2704. This is repeated 6 more times..
Sorry if my logic is wrong but I included comments in the code itself so what I am talking about. Thanks for the tips/help so far! :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
using namespace std;
int main()
{
int years_Pro = 6;
double membership_Fee = 2500;
for (int i = 1; i < 6; i++)
{
cout << "Year: " << i << " which costs: " << membership_Fee << endl;
membership_Fee = membership_Fee + (membership_Fee * .04);
}
return 0;
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
using namespace std;
int main()
{
int years_Pro = 6;
double membership_Fee = 2500;
for (int i = 1; i < 6; i++)
{
membership_Fee = membership_Fee + (membership_Fee * .04); // Can it go here also, or is it practical the other way?
cout << "Year: " << i << " which costs: " << membership_Fee << endl;
}
return 0;
}
|