-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