无限循环,我不知道为什么
Infinite loop and i dont know why
我正在学校实验室工作,我似乎无法弄清楚为什么代码一直进入无限循环。我知道while语句有问题,但我看不出它是什么。
#include <iostream>
using namespace std;
int main()
{
int c = 0, p = 0, prof;
cout << "Do you like Coke or Pepsi? " << endl;
cin >> prof;
//put in data validation
while (prof != 'q' && prof != 'Q')
{
if (prof == 'p')
p++;
else if (prof == 'c')
c++;
cout << "Do you like Coke or Pepsi? " << endl;
cin >> prof;
}
if (p > c)
cout << "Pepsi Wins";
else if (p < c)
cout << "Coke Wins";
else
cout << " It's a tie";
system("Pause");
}
只是变量prof
应该是char
而不是int
char prof;
相关文章:
- 我正在使用嵌套的while循环来解析具有多行的文本文件,但由于某种原因,它只通过第一行,我不知道为什么
- 我不知道为什么这段代码会让核心被转储?
- 没有函数模板的实例与我不知道为什么的参数列表匹配
- if-else 语句仅按特定顺序工作,我不知道为什么
- DirectX 11 引擎在第三次代码改进后没有突然运行,我不知道为什么
- 函数抛出seg错误,我不知道为什么
- 我不知道为什么复制构造函数的调用在 c++ 中不稳定
- 随着时间的推移,我的程序越来越慢,我不知道为什么.内存泄漏
- "错误:在'.标记'之前出现预期的主表达式,我不知道为什么
- 我正在制作c ++代码,但发生错误我不知道为什么
- std::cout << glGetString(GL_RENDER) << std::endl;抛出错误但不GL_Renderer或GL_Verision,我不知道为什么?
- 我的Arduino串行命令行不起作用,我不知道为什么
- 我正在编写一个拆分为 3 的合并排序,我不知道为什么它不起作用
- 为什么我的结果中有 0?我不知道它从哪里来
- 我不知道为什么我的矢量无法推回
- 语法检查器指出一些我不知道为什么的错误
- 我不知道为什么我的字符串无法保存值
- 编写蒙特卡洛集成程序,我不知道为什么我会收到某些错误
- 我不知道为什么会发生堆损坏(关于内存分配问题)
- 库特是空的,我不知道为什么