Simple program help

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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//guesses age

#include <iostream>
#include <string>

using namespace 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;
		}
		else if (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.
i use the year 2011 because if you use 2012 it displays one year older
From what I see in your code the error you have is because you interpret what this code is doing wrong.
1
2
3
        bool yesNo;
	cout << "\n\nHave you had your birthday yet this year? (y,n) ";
	cin >> yesNo;


I would expect
1
2
3
4
5
6
7
8
9
10
11
12
13
       char yesNo = (char)0;
       cout << "\n\nHave you had your birthday yet this year? (y,n) ";
       cin >> yesNo;
       yesNo = tolower(yesNo);
    
       do
       {
              birthday = 0;
              if(yesNo == 'y')
              {
                     birthday =1;
              }
       } while( (yesNo != 'y') && (yesNo != 'n') )


I don't know if this will help you.
Much obliged it worked.
Topic archived. No new replies allowed.