Simple Variable Problem

• 11-11-2005
Cthulhu
Simple Variable Problem
I'm very very new at programming, and I am attempting to make a simple (I thought) program that asks the user the current year, their age. It would then output the year in which they were born. +/- a year, depending on when the birthday falls... But I'll fix that later.

The issue is, BirthYear *always* returns 23. I can't figure it out. I suspect I'm doing something wrong here:

Code:

`int BirthYear = CurrentYear - Age;`
But here is the complete program in case that is not the problem.

Code:

```#include <iostream> using namespace std; int AskWhatYear (); int AskAge (); int main() {      int Age;   int CurrentYear;   AskAge();   AskWhatYear();   int BirthYear = CurrentYear - Age;   cin.get();   cout<<"\nYou were probably born in "<< BirthYear;   cin.get();      } int AskAge() // Asks the users age. {   int Age;   cout<<"\nPlease enter your age: ";   cin>> Age;   cin.ignore();   return Age; } int AskWhatYear() // Asks the user what year it is. {   int CurrentYear;   cout<<"\nPlease enter the current year: ";   cin>> CurrentYear;   cin.ignore();   return CurrentYear; }```

I'm sure there are other noob mistakes in there that work, but aren't the ideal way to do it. I'm open to al suggestions :)
• 11-11-2005
mrafcho001
the only thing wrong with it is that you did not asign "Age" and "CurrentYear" in the main function a value.

Code:

```#include <iostream> using namespace std; int AskWhatYear (); int AskAge (); int main() {      int Age;   int CurrentYear;   Age = AskAge();   CurrentYear = AskWhatYear();   int BirthYear = CurrentYear - Age;   cin.get();   cout<<"\nYou were probably born in "<< BirthYear;   cin.get();      } int AskAge() // Asks the users age. {   int Age;   cout<<"\nPlease enter your age: ";   cin>> Age;   cin.ignore();   return Age; } int AskWhatYear() // Asks the user what year it is. {   int CurrentYear;   cout<<"\nPlease enter the current year: ";   cin>> CurrentYear;   cin.ignore();   return CurrentYear; }```
• 11-11-2005
Cthulhu
Thank you very much. Works great now.

I new it was going to be simple, but after going over it numerous times, I couldn't see what it might be.

Thanks again :)

/me bows