Please tell me how to do this. I am trying to make a program that displays your age using simple math, I'm trying to make it to where it asks if you've had your birthday or not this year, and if you have it adds a 1 to the age. This is my code:
//guesses age
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int year(2011);
string name;
int birthYear;
int birthday = 0;
bool yesNo;
system("clear");
cout << "Please enter your first name:";
cin >> name;
cout << "\n\nPlease enter the year you were born: ";
cin >> birthYear;
cout << "\n\nHave you had your birthday yet this year? (y,n) ";
cin >> yesNo;
yesNo = tolower(yesNo);
int age (year - birthYear);
//adds a 1 if you've had your birthday yet
do
{
if (yesNo = true)
{
birthday = 1;
}
elseif (yesNo = false)
{
birthday = 0;
}
} while (!yesNo); //loops while there is no value for 'yesNo'
cout << "\n\nHello, " << name << ". If my calculations are correct, ";
cout << "\nyou should be " << age + birthday << " years old. \n\n";
return 0;
}
also, if possible, help me make it to where if you don't enter, a y or n for if you've had your birthday yet, it says "that is not a valid answer." I appreciate all the help put forth.