I am trying to write to a program that will compute the current age of the one executing the program. It is done by asking 2 questions:
- What is the current year
- What is your birth year
After these have been entered by the user the current age of the user needs to be computed.
I accomplished it because it is not all that difficult. However I want to do it according to standards and I would like to have the function prototype above main and the actual function definition below main. I am however not able to get it to work.
This is what I have now but if I do it like this the 'cout part' is being displayed but only the text 'this is your age now'. Judging by this I guess something is wrong with the part on the next line: cout << x (a, b) << endl;
Does anybody have any suggestions?
This is what I have now:
#include <vcl.h> //needed for Borland
#include <iostream> //needed for input output
using namespace std;
//---------------------------------------------------------------------------
int x (int, int); /* function declaration
or prototype */
int main()
{
int a; //declaration variables
int b; //declaration variables
cout << "Type current year here: ";
cin >> a;
cout << "Type year of birth: ";
cin >> b;
cout << "This is your age now: ";
cout << x (a, b) << endl;
return 0;
}
int x (int a, int b) // function definition
{
int x = (a - b);
int d;
cin >> d;
return x;
}
- What is the current year
- What is your birth year
After these have been entered by the user the current age of the user needs to be computed.
I accomplished it because it is not all that difficult. However I want to do it according to standards and I would like to have the function prototype above main and the actual function definition below main. I am however not able to get it to work.
This is what I have now but if I do it like this the 'cout part' is being displayed but only the text 'this is your age now'. Judging by this I guess something is wrong with the part on the next line: cout << x (a, b) << endl;
Does anybody have any suggestions?
This is what I have now:
#include <vcl.h> //needed for Borland
#include <iostream> //needed for input output
using namespace std;
//---------------------------------------------------------------------------
int x (int, int); /* function declaration
or prototype */
int main()
{
int a; //declaration variables
int b; //declaration variables
cout << "Type current year here: ";
cin >> a;
cout << "Type year of birth: ";
cin >> b;
cout << "This is your age now: ";
cout << x (a, b) << endl;
return 0;
}
int x (int a, int b) // function definition
{
int x = (a - b);
int d;
cin >> d;
return x;
}
Comment