Need help (ASAP)

hey again i have small problem i need help i want to print the "year with greatest and smallest increase and decrease" the years are from 2000 to 2009. i know how to print the greatest and smallest number in the array but i don't know how to print the year. here is half of the code of the program the one that's important for you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void maxIncDecYears(int annualIncome[],int arraySize){
    year = 2000;

    int max = annualIncome[0],min = annualIncome[0];

    for(int z = 1; z < arraySize; z++){
        if(max < annualIncome[z]){
            max = annualIncome[z];
            year++;
        }

    }
    cout << "Year with maximum income increased: " << year << endl;

    year = 2000;

    for(int x = 1; x < arraySize; x++){
        if(min > annualIncome[x]){
            min = annualIncome[x];
            year++;
        }

    }
    cout << "Year with maximum income decreased: " << year << endl;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void maxIncDecYears(int annualIncome[],int arraySize)
{
    int greater_year = 2000;
    int min_year = 2000;

    int max = annualIncome[0],min = annualIncome[0];

    for(int z = 1; z < arraySize; z++){
        if(max < annualIncome[z]){
            max = annualIncome[z];
            greater_year++;
        }

    }
    cout << "Year with maximum income increased: " << greater_year << endl;

    min_year = 2000;

    for(int x = 1; x < arraySize; x++){
        if(min > annualIncome[x]){
            min = annualIncome[x];
            min_year++;
        }

    }
    cout << "Year with mimum income decreased: " << min_year << endl;
}

one quick question ..why are you passing array to the function when you are using only int .. it effact the performance
Last edited on
Topic archived. No new replies allowed.