我已经准备好了所有的东西,但我有一个问题,我的教授要我们问用户放入多少份,我的问题在这里:
string recipeName, userInputStr, servingNumber;
int userInputInt;
double totalCals, totalCarbs;
// initialize accumlator variables
totalCals = 0.;
totalCarbs = 0;
// asking for name of recipe and number of servings
cout << "What is the name of your recipe? ";
getline(cin, recipeName);
cout << "How many servings would you like? ";
getline(cin, servingNumber);
istringstream(servingNumber) >> totalCals, totalCarbs;
if (servingNumber<1 || servingNumber>10)
{
cout << "You have entered the wrong answer. " << endl;
return 0;
}
更具体地说,它在这里:
if (servingNumber<1 || servingNumber>10)
我在 < 和 > 上不断收到错误消息,说“没有运算符与这些操作数匹配”
有人告诉我我应该将字符串 servingNumber 转换为 int 然后比较它,但它不是在这里转换的吗?:
istringstream(servingNumber) >> totalCals, totalCarbs;
然后在 if 语句上进行比较?
我不确定我在做什么错..