I'm taking a CSCI Programming class and I need help with an Assignment!

Mar 15, 2014 at 5:26am
For this assignment I have to:
Write a C++ program that prompts a user to input the birth year (i.e. 1998). Based on the current year, determine if the
person is of voting age. (Voting age being 18.) If the person is not of voting age, you are to display the following message:
Sorry, but you cannot vote at this time.
You have 4 year(s) until you can vote.

(Where 4 is a calculated value that represents the number of years remaining until the person can vote.)

If the person is of voting age, you are to display the following message:
Congratulations!!! You are 22 years old.
You are of voting age.
(Where 4 is a calculated value that represents the number of years remaining until the person can vote.)
Mar 15, 2014 at 6:18am
What exactly do you need help with? What code have you written so far?
Last edited on Mar 15, 2014 at 6:18am
Mar 15, 2014 at 2:01pm
Here's part of your answer...

1
2
3
4
5
6
7
8

bool CanIVote(myBirthYear)
{
  int diff = 2014 - myBirthYear;
  if (diff >= 18) return true;
  return false;
}


or the shorter version...

1
2
bool CanIVote(myBirthYear)
  { return ((2014-myBirthYear) >= 18) ? true : false; }
Last edited on Mar 15, 2014 at 2:04pm
Topic archived. No new replies allowed.