However I want to do it according to a standard I used before to write a program which asked a user to enter the current year and his birthyear after which the current age of the user was computed and written to the screen.
I got some help with the second program from some of you, thanks for that and have now been working a substantial part of the evening on the other program.
The idea is that I build the program like this (this should be the standard):
function protocol.
main section with actual function in it.
function definition.
This is the program which computes the current age (this program works fine and is according to the standard I would like to use):
Expand|Select|Wrap|Line Numbers
- #include <iostream> //needed for input output
- using namespace std;
- //---------------------------------------------------------------------------
- int CalculateAge (int, int); //function prototype
- int main()
- {
- int currentyear; //declaration variables
- int birthyear; //declaration variables
- cout << "Type current year here: ";
- cin >> currentyear;
- cout << "Type year of birth: ";
- cin >> birthyear;
- cout << "This is your age now: ";
- cout << CalculateAge (currentyear, birthyear) << endl;
- system("pause");
- return 0;
- }
- int CalculateAge (int current_year, int birth_year) // function definition
- {
- int age = (current_year - birth_year);
- return age;
- }
This is the program which computes the average:
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- using namespace std;
- int CalculateAverage (int, int, int, int, int); //protocol
- int Average (int , int); // protocol
- int main()
- {
- int integer1;
- int integer2;
- int integer3;
- int integer4;
- int integer5;
- cout << "type the first: ";
- cin >> integer1;
- cout << "type the second: ";
- cin >> integer2;
- cout << "type the third: ";
- cin >> integer3;
- cout << "type the fourth: ";
- cin >> integer4;
- cout << "type the fifth: ";
- cin >> integer5;
- system("pause");
- cout << "Average is: " << Average (int, int) << endl; // actual function
- return 0;
- }
- int CalculateAverage (int integer_1, int integer_2, int integer_3, int integer_4, int integer_5)
- {
- int average = (int integer_1 + int integer_2 + int integer_3 + int integer_4 + int integer_5);
- int average = (average / 5)
- return average;
- }