The program should start by asking the user to enter the company’s annual income for each year starting from year 2000 till 2009. Income must be taken in million. Implementation of following user defined functions are mandatory for this program:
A function GetAnnualIncome(), which will take and store the income for each year in an input array. The input entered by user should be integer only. The input array should be passed as argument to the function. While taking the input, if annual income entered by the user is a negative value, the program should prompt the user to enter the income again for that year.
function CalcIncChange(), which will take two arrays as its arguments. This function will calculate the increase or decrease in the annual income of the company for each year by subtracting the current year income from the income of previous year. For example, to calculate income increase or decrease for year 2001, the following formula can be used:
Income increase or decrease for year 2001 = Income of Year 2001 – Income of Year 2000
M confuse in this problem..
i have to do any thing in main program??
and how i will get two arguemnts
To enter the incomes for each year, you would want a for loop that runs, and this is where you store the values into some array.
As for the "two arguments" part, it sounds like they want you to have one argument as the array you already filled, and the second argument is the array that will be filled with the "income decrease or increase" amounts.
You call the other functions *from* your main function, but the arrays will need to be created in your main function and passed in.
You send the income array to the getannualincome() function, to be filled, then send the income array, along with a difference array, to the calcIncChange() function, to figure the differences.. In main(), you print out the results.
#include <iostream>
using std::cout;
using std::endl;
void GetAnnualIncome(int income[10])
{
cout << "We ask for annual income here, but to make this quicker, we'll auto-fill it!" << endl;
for(int x=0;x<10;x++)
income[x] = 1+rand()%20;
}
void CalcIncChange(int income[10], int difference[10])
{
for(int x=1;x<10;x++)
difference[x] = income[x]-income[x-1];
}
int main()
{
int income[10];
int difference[10];
GetAnnualIncome(income);// Fill array with annual incomes
CalcIncChange(income, difference); // Calculate differences
cout << "Year 2000 : Income was " << income[0] << " million" << endl;
// Print this out of for loop as there is nothing to compare with for previous year
for(int x=1;x<10;x++) // for years 2001 to 2009
{
cout << "Year " << 2000+x << " : Income was " << income[x] << " million showing a";
if(income[x] < income[x-1])
cout << " decrease of ";
elseif(income[x] > income[x-1])
cout << "n increase of ";
else
cout << " change of ";
cout << difference[x] << " million" << endl;
}
return 0;
}