-3
当用户添加他要重复循环次数时,产生错误的一个周期错误,但他不断重复的周期没有结束我在C++
这里是代码
#include <iostream>
using namespace std;
int main()
{
char resp, copcion, varied, tprod;
int cfab, ncod, num;
cout << "How many products do you want to register ?, enter the respective number";
cin >> num;
while (num > 0)
{
cout << "Enter the product type If you are a Child (n) or Adult (a)";
cin >> tprod;
if ((tprod != 'n') && (tprod != 'N') && (tprod != 'a') && (tprod != 'A'))
{
cout << "ERROR: The product type is only Children (n) or Adults (a)" << endl;
}
cout << "Enter your Variety for Salted (s) and Sweets (d)";
cin >> varied;
if ((varied != 'd') && (varied != 'D') && (varied != 's') && (varied != 'S'))
{
cout << "ERROR: The variety of products are only Sweets (d) or Salted (s)" << endl;
}
//Code range
//Salted 1 to 10
//Sweets 11 to 20
cout << "Enter the product code you wish to assign";
cin >> ncod;
if (ncod > 20)
{
cout << "ERROR: There is a range of numbers, you exceeded that amount" << endl;
}
cout << "Enter the respective amount";
cin >> cfab;
if (cfab = 0)
{
cout << "ERROR: Amount entered is not valid";
}
}
return 0;
}
提前感谢您解决疑惑。
'cfab = 0' - >'cfab == 0'? – LogicStuff
用于此目的的最佳工具是您的调试器。 – Charles
@Charles Eclipse已经将它标记为一个潜在的问题,当我将代码复制/粘贴到自动格式化代码时。 – mch