Как сделать, чтобы при вводе данных "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;
}
Answers & Comments
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;
На скрине показано куда вставлять код.