【发布时间】:2014-01-25 09:29:00
【问题描述】:
无论我输入 Y 还是 N,我的程序都会在我回答“更多肉?”后结束我希望它能够将响应返回给循环。
#include <iostream>
using namespace std;
int main()
{
char response = 'y';
double price;
double total = 0;
while (response == 'Y' || 'y') {
cout << "Please enter price of meat: ";
cin >> price;
total += price;
cout << "More meat? (Y/N)";
cin >> response;
return response;
}
cout << "Your total is: " << total;
return 0;
}
【问题讨论】:
-
(response == 'Y' || 'y') 应该是 (response == 'Y' || response =='y')
标签: c++ loops while-loop return response