The couts works fine, the problem is that it never enters the
if
statements that contain the couts.
In line 59
if(annualIncome[j] > annualIncome[j++]){
Here you are comparing
annualIncome[j]
to
annualIncome[j]
and then incrementing
j
. Since they are equal, the if statments are not satisfied and you are not going to output that cout.
Since you already increment
j
in the
for
loop, I don't think this was your intent. I recommend replacing this function with the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
void calcIncChange(int annualIncome[],int incChange[]){
year = 2000;
for(int j = 0; j < 10; j++){
if(annualIncome[j] > annualIncome[j+1]){
incChange[j] = annualIncome[j] - annualIncome[j+1];
cout << "Income decrease in year " << year << ": \t" << incChange[j] << " million";
}
else if(annualIncome[j] < annualIncome[j+1]){
incChange[j] = annualIncome[j+1] - annualIncome[j];
cout << "Income increase in year " << year << ": \t" << incChange[j] << " million";
}
}
}
|
If we increment
j
inside the
if
statements, then we really have no idea what
j
is going to be at the end of each loop and it starts to get messy, just check the value of
j+1
not
j++
.
Edit: if you REALLY want to increment
j
like this, then use
++j
. This will increment
j
and then return its value. So line 59 would compare
annualIncome[j]
with
annualIncome[j+1]
and
j
would remain one higher than before.