0

How can I fix my if statements to worK?

I created a calculator to produce your birthday as of today. However, I am trying to set limits based on month and days. For example if June 31st was entered the program would recognize it is not correct as that date does not exist. When i wrote the if statements, only my first IF statement for January and the last one for December works. Please if you can look through the program and let me know what I am missing. program: int main() { int age; int currentyear=2018, currentmonth=05, currentday=25; int birthyear, birthmonth, birthday; cout <<"Enter your birth year: "; cin >> birthyear; cout <<"Enter your birth month in the format MM: "; cin >> birthmonth; cout <<"Enter birth day in the format DD: "; cin >> birthday; age = ((currentyear*10000 + currentmonth*100 + currentday) - (birthyear*10000 + birthmonth*100 +birthday))/10000; if (birthmonth == 1 && birthday < 01 || birthday >32) cout << "Oops, looks like the date you entered does not exist!"; else if (birthmonth == 2 && birthday < 01 || birthday >31) cout << "Oops, looks like the date you entered does not exist!"; else if (birthmonth == 3 && birthday < 01 || birthday >32) cout <<"Oops, looks like the date you entered does not exist!"; else if(birthmonth == 4 && birthday < 01 || birthday > 31) cout <<"Oops, looks like the date you entered does not exist!"; else if (birthmonth == 5 && birthday < 01 || birthday > 32) cout << "Oops, looks like the date you entered does not exist!"; else if (birthmonth == 6 && birthday < 01 || birthday >31) cout <<"Oops, looks like the date you entered does not exist!"; else if(birthmonth == 7 && birthday < 01 || birthday > 32)

25th May 2018, 10:05 PM
shamizzle
2 ответов
+ 1
shamizzle Sorry but you must share long code by save they in code section and post here his link... In this way we can easly read and execute it for help you
25th May 2018, 10:38 PM
KrOW
KrOW - avatar
0
The code was too long so here is the ending and remaining part: if (birthmonth == 8 && birthday < 01 || birthday >32) cout <<"Oops, looks like the date you entered does not exist!"; else if(birthmonth == 9 && birthday < 01 || birthday > 31) cout <<"Oops, looks like the date you entered does not exist!"; else if (birthmonth == 10 && birthday < 01 || birthday > 32) cout << "Oops, looks like the date you entered does not exist!"; else if (birthmonth == 11 && birthday < 01 || birthday >31) cout <<"Oops, looks like the date you entered does not exist!"; else if(birthmonth == 12 && birthday < 01 || birthday > 32) cout <<"Oops, looks like the date you entered does not exist!"; else cout << "You are " << age << " years old as of May 25, 2018!" <<endl; }
25th May 2018, 10:09 PM
shamizzle