所以当我输入我想要使用的月份,比如12月,并且我把722作为小时,程序就会说:“你输入的小时数不能超过月内的小时数720“。有没有办法解决?我不想每个月都做一些陈述,我觉得有一个更简单的方法。这也是我第一次上大学的程序这个字符串比较不起作用
int userPackage, userHours; //Declaring integer variables
double savings, savings2, total; //Declaring double value
string userMonth;
cout<<"\tHello.\nEnter the number of the package you have\n1) Package A\n2) Package B\n3) Package C\n"; //Prompts the user for their package in a menu like fashion
cin>>userPackage; //gets package
if(userPackage > 3 || userPackage < 1) //Error output for numbers that don't match packages
{
cout<<"Error, invalid choice";
return 0;
}
cout<<"Enter the number of hours you have been online."; //Propmts the user for the number of hours they've been online
cin>>userHours; //gets hours
cout<<"Enter the month (by name): ";
cin>>userMonth;
cout<<"\n";
if(userMonth == "January","March","May","July","August","October","December")
{
if (userHours > 744)
{
cout<<"The amount of hours you entered cannot exceed the amount of hours within the month 744";
return 0;
}
}
if(userMonth == "April", "June", "September", "November");
{
if(userHours > 720)
{
cout<<"The amount of hours you entered cannot exceed the amount of hours within the month 720";
return 0;
}
}
if(userMonth == "February");
{
if (userHours > 672)
{
cout<<"The amount of hours you entered cannot exceed the amount of hours within the month 672";
return 0;
}
}
userMonth ==“一月”,“三月”,“五月”,“七月”,“八月”,“十月”,“十二月”这不是你如何比较字符串与多种可能性。您可以将这些字符串存储在静态常量数组或集合中,并查找该字符串是否在其中。 –
'if(userMonth ==“April”,“June”,“September”,“November”);'我打赌你从来没有在任何书,教程,网站等上看到过这样的if语句。声称是教C++。那么你是怎么想出来的呢? – PaulMcKenzie