c++ - 我以前用过一种方法,现在同样的方法不起作用
问题描述
这是我的代码。
string HCoffees;
cout
<< "\nPlease choose one of these hot coffees. Type your selection here: "
<< flush;
while (cin.get() != '\n')
;
getline(cin, HCoffees);
cout << "\nNow at the " << HCoffees << " section.\n" << endl;
//If the selection is a Caffe Americano...
if (HCoffees == "Caffe Americano" || HCoffees == "caffe americano"
|| HCoffees == "Caffe americano" || HCoffees == "caffe Americano") {
cout << "\nWhat size Caffè Americano would you like? " << flush;
string size;
cin >> size;
if (size == "Tall" || size == "tall") {
cout << "That will be 2.25.\n\nHow many Caffè Americanos (Tall size) would you like to get?" << flush;
}
else if (size == "Grande" || size == "grande") {
cout << "That will be 2.65.\n\nHow many Caffè Americanos(Grande size) would you like to get?" << flush;
}
else if (size == "Verti" || size == "verti") {
cout << "That will be 2.95.\n\nHow many Caffè Americanos(Verti size) would you like to get?" << flush;
} else {
cout << "Size not avaliable. Chose a different size: " << flush;
}
}
}
即使在控制台中输入了 Caffe Americano(用户输入了此选项),它也不会打印出“您想要哪种尺寸的 Caffe Americano?” (如果键入 Caffe Americano,这就是我在第 13 行编写的程序)。我原以为我获取用户输入的方式有问题,但我错了,因为我之前已经在我的程序中使用了相同的输入代码*,并且它起作用了。请尝试解决这个问题。谢谢!
*输入代码也如上所示:
string HCoffees;
cout
<< "\nPlease choose one of these hot coffees. Type your selection here: "
<< flush;
while (cin.get() != '\n')
;
getline(cin, HCoffees);
cout << "\nNow at the " << HCoffees << " section.\n" << endl;
解决方案
推荐阅读
- ios - Obj-C - 如果语句被触发,即使它不是真的?
- python - 当我已经有了模块并且错误提示:ModuleNotFoundError?
- reactjs - 如何在上下文提供程序中使用 axios get 调用来做出反应
- html - 如何通过 LAN 流式传输 360 视频文件并将其嵌入到我的 HTML 网站中?
- python-3.x - 如何在另一个函数中访问我的 gui 类中的条目变量?
- c - 如何从控制台为 getc 输入十六进制值
- java - 确定将 JedisPool 与布尔变量一起使用
- javascript - 如何将道具/状态从 React Link 传递到功能组件?
- angular - environment 与 useValue 的常量
- emacs - Emacs speedbar 不显示所有文件类型,例如 .bin