every thing is working fine except when I input date between Dec 20 -Feb 19
when i input date between this it returns the date from function stars.. line 71
HELP ME PLZZZ!!!
Code:#include <iostream> #include <string> #include <stdlib.h> using namespace std; int stars(int date, int month); int check(const char* arr); int main() { string arr; int cont=1; int chck,date,month; string segment[]= {"WOOD","FIRE", "EARTH","GOLD","WATER"}; string animal[]= {"DOG","CAT","RAT","TIGER","MONKEY"}; while (1) { cout << "Enter your Date of Birth OR 0 to exit\n(Format: DD/MM/YYYY e.g: 11/09/1984): "; getline(cin,arr); date=((arr[0]-'0')*10)+(arr[1]-'0'); month=((arr[3]-'0')*10)+(arr[4]-'0'); if (arr == "0") { cout << "Thankyou for using... :)"; exit(1); } else { if (arr.length() != 10 ) { cout << "\nSyntax Error! Please follow the syntax\n\n"; continue; } chck = check(arr.c_str()); if(chck != 0) // Checking the errors in syntax { if (chck == 1) { cout << "\nError in Date. Please try again and follow the syntax\n"; } if (chck == 2) { cout << "\nError in Month. Please try again and follow the syntax\n"; } if (chck == 4) { cout << "\nError in Syntax. Please try again and follow the syntax\n"; } cont=1; } } int temp=stars(date,month); cout << temp << "You are" << segment[(stars(date,month))] << "/" << animal[(stars(date,month))] << endl; //cout << date << endl << month ; } return 0; } int stars(int date, int month) { if( (month == 12 && date >=20) || (month == 11 )|| (month == 2 && date <= 19) ) { return 0; //WOOD } if ( month >= 2 && month <= 4) { if(month == 2 && date >= 20 ||month ==3 || month == 4 && date <= 19) { return 1; // FIRE } } if ( month >= 4 && month <= 7 || month == 5 || month == 6) { if(month == 4 && date >= 20 || month == 7 && date <= 19) { return 2; // EARTH } } if ( month >= 7 && month <= 10 || month == 8 || month ==9) { if(month == 7 && date >= 20 || month == 10 && date <= 19) { return 3; // GOLD } } if ( month >= 10 && month <= 12 || month == 11) { if(month == 10 && date >= 20 || month == 10 && date <= 12) { return 4; // Water } } } int check(const char* arr) { if (arr[0] < '0' || arr[0] > '3' || arr[1] < '0' || arr[1] > '9' || ( arr[0] == '3' && (arr[1] != '0' || arr[1] != '1') )) { return 1;// Date problem } if ( arr[3] < '0' || arr[3] > '1' || arr[4] < '0' || arr[4] > '9' || (arr[3] == '1' && (arr[4] <'0' || arr[4] > '2'))) { return 2; // month problem } if( arr[2] != '/' && arr[5] != '/') { return 4; } return 0; }



LinkBack URL
About LinkBacks



