Help Please!!

Why is answer undefined??


#include <iostream>
using namespace std;


bool validMonth(int number);
bool validDay(int numb);

int main ()
{
cout << "This C++ program prints the day number of the year,\n";
cout << "give the date in the form of month, then day,\n";
cout << "then year\n\n";
cout << "Enter date in form: month day year:\n\n";
do{
int month;
int day;
char answer;
int number;
int numb;

cout << "Enter month : ";
cin >> month;

while (!validMonth(number)){
cout << month << " is an invalid month number\n\n\n";
cout << "Try another date Y/N ---> ";
cin >> answer;
}
cout << "Enter day : ";
cin >> day;
while (!validDay(numb)){
cout << day << " is an invalid day number\n\n\n";
cout << "Try another date Y/N ---> ";
cin >> answer;
}
}
while (answer != 'n' && answer !='N')

return 0;
}

bool validMonth (int number){
return (number >=1 && number <=12);
}
bool validDay (int numb){
return (numb >=1 && numb <=31);
}
closed account (48T7M4Gy)
Why is answer undefined??

Probably because question is undefined.
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) You define answer inside your do-while loop:

1
2
3
4
5
do{
    int month;
    int day;
    char answer;
    [...]


So it's only defined inside that loop.
Take a really good look at this http://www.cplusplus.com/doc/tutorial/functions/ and all your problems will disappear.
Topic archived. No new replies allowed.