Help! Problem with bool returns and loops?

I guess I'm not sure what my problem is here. The following program is based on a class assignment, but I added a few things to make it a little smarter. The program asks for a birth date, and the outputs the user's horoscope.

I added a function to ensure that the user inputs an actual birth date, and I called the function before the horoscope is outputted. The program appears to work fine if the user enters a real birth date, but if an erroneous date is entered, like January 38th, the program will display the text, "Please enter an appropriate birthdate" but then it carries on outputting the horoscope for the inputted parameters. Something about this [ if(bool verifyDate = true) ] has got to be wrong.

Like I said, I've only been in C++ class for two weeks now, so I'm probably missing something super easy. Thanks for your thoughts! Also, sorry I couldn't get the text aligned correctly. First time poster...


#include <iostream>
using namespace std;

int month;
int day;
char loop;

bool verifyDate() // Ensures that the user enters a feasible birthdate
{
if(month > 12){
cout << endl << "Please enter an appropriate month.";
return false;}
else if((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && day > 31){
cout << endl << "Please enter an appropriate birthdate.";
return false;}
else if((month == 4 || month == 6 || month == 9 || month == 11) && day > 30){
cout << endl << "Please enter an appropriate birthdate.";
return false;}
else if(month == 2 && day > 28){
cout << endl << "Please enter an appropriate birthdate.";
return false;}
else
return true;
}

int main()
{
cout << "Please enter your birthmonth as a number, 1 to 12: ";
cin >> month;

if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){ // Allows the user to select from the correct date range for each month
cout << "Please enter the day on which you were born as a number, 1 to 31: ";
cin >> day;
cout << endl;}
else if (month == 4 || month == 6 || month == 9 || month == 11){
cout << "Please enter the day on which you were born as a number, 1 to 30: ";
cin >> day;
cout << endl;}
else if (month == 2){
cout << "Please enter the day on which you were born as a number, 1 to 28: ";
cin >> day;
cout << endl;
}

verifyDate();

if(bool verifyDate = true){

cout << endl;

if(month == 3 && day >= 21 || month == 4 && day <= 19)
cout << "Lorem Ipsum...";
else if(month == 4 && day >= 20 || month == 5 && day <= 20)
cout << "Lorem Ipsum...";
else if(month == 5 && day >= 21 || month == 6 && day <= 21)
cout << "Lorem Ipsum...";
else if(month == 6 && day >= 22 || month == 7 && day <= 22)
cout << "Lorem Ipsum...";
else if(month == 7 && day >= 23 || month == 8 && day <= 22)
cout << "Lorem Ipsum...";
else if(month == 8 && day >= 23 || month == 9 && day <= 22)
cout << "Lorem Ipsum...";
else if(month == 9 && day >= 23 || month == 10 && day <= 22)
cout << "Lorem Ipsum...";
else if(month == 10 && day >= 23 || month == 11 && day <= 21)
cout << "Lorem Ipsum...";
else if(month == 11 && day >= 22 || month == 12 && day <= 21)
cout << "Lorem Ipsum...";
else if(month == 12 && day >= 22 || month == 1 && day <= 19)
cout << "Lorem Ipsum...";
else if(month == 1 && day >= 20 || month == 2 && day <= 18)
cout << "Lorem Ipsum...";
else if(month == 2 && day >= 19 || month == 3 && day <= 20)
cout << "Lorem Ipsum...";
}

cout << endl << endl << "Would you like to repeat the program (Y/N)? ";
cin >> loop;
cout << endl;

return 0;
}
Instead of:
1
2
3
verifyDate();

 if(bool verifyDate = true)

Try:
if(verifyDate())

The reason is, you are declaring a bool variable that only exists within the scope of the if statement. Then it assigns true to the bool and the assignment operator returns the value true. If sees the true and carries on like it should. So in other words that if statement would be true every time. However calling your function that returns a bool inside the if would not be true every time.
Dang, that was quick! I knew there was something fishy about that line. Thanks so much for the help!
Topic archived. No new replies allowed.