Как сделать, чтобы при вводе данных "31 февраля" выдало "неизвестная операция"? с++ // 2.cpp: определяет точку входа для консольного приложения. #include "stdafx.h" #include using namespace std; int main() { int month, day; cout < < "programma opredeleniya znaka zodiaka" < < endl; cout < < "vvedite mecyac: "; cin > > month; cout < < "vvedite den: "; cin > > day; switch (month) { case 1: if (day < 21) cout < < "kozerog" < < endl; else cout < < "vodoley" < < endl; break; case 2: if (day < 19) cout < < "vodoley" < < endl; else cout < < "ryby" < < endl; break; case 3: if (day < 21) cout < < "ryby" < < endl; else cout < < "oven" < < endl; break; case 4: if (day < 20) cout < < "oven" < < endl; else cout < < "telec" < < endl; break; case 5: if (day < 21) cout < < "telec" < < endl; else cout < < "bliznecy" < < endl; break; case 6: if (day < 22) cout < < "bliznecy" < < endl; else cout < < "rak" < < endl; break; case 7: if (day < 23) cout < < "rak" < < endl; else cout < < "lev" < < endl; break; case 8: if (day < 23) cout < < "lev" < < endl; else cout < < "deva" < < endl; break; case 9: if (day < 23) cout < < "deva" < < endl; else cout < < "vesy" < < endl; break; case 10: if (day < 23) cout < < "vesy" < < endl; else cout < < "skorpion" < < endl; break; case 11: if (day < 23) cout < < "skorpion" < < endl; else cout < < "strelec" < < endl; break; case 12: if (day < 22) cout < < "strelec" < < endl; else cout < < "kozerog" < < endl; default: cout < < "neizvestnaya operaciya"< } system("pause"); return 0; }
using namespace std;
int main() {
int month, day;
string a[13] = {"Kozerog","Vodoley","Ryby","Oven","Telec","Bliznecy",
"Rak","Lev","Deva","Vesy","Skorpion","Strelec","Kozerog"};
int mes[12] = {31,29,31,30,31,30,31,30,31,31,30,31};
int bound[12] = {21,19,21,20,21,22,23,23,23,23,23,22};
cout << "Programma opredeleniya znaka zodiaka" << endl;
cout << "Vvedite mecyac: ";
cin >> month;
cout << "Vvedite den: ";
cin >> day;
if ((month<1 || month>12) || (day<1 || day>mes[month-1]))
cout<<"invalid input"<<endl;
else {
if (day<bound[month-1]) cout<<a[month-1]<<endl;
else cout<<a[month]<<endl;
}
system("pause");
return 0;
}
И в конце вместо
"default: cout << "Neizvestnaya operaciya"< }"
Должно быть
"default: cout << "Neizvestnaya operaciya"<< endl; }"
case 2:if (day <19) cout << "Vodoley" << endl;else if (day >= 19 && day <= 29)cout << "Ryby" << endl;else { cout << "Neizvestnaya operaciya" << endl; } break;
На скрине показано куда вставлять код.