几个月前,我用C ++制作了一个示例销售点系统。现在,我已经了解了更多有关C ++的知识,我试图对它进行更好的复制。但是,我没有从程序的“签出”部分中使用的ifStatement中获得行为。我想要的是让程序在用户输入“ y”时退出,并让其返回到其他任何输入的主菜单。但是,它只是退出任何输入。我对C ++还是很陌生,不明白为什么。任何帮助,将不胜感激。我已将代码包含在此帖子中。
#include <iostream>
使用命名空间标准;
int main(int nNumberofArgs,char * pszArgs []) {
int nBookQuantity = 0;
int nBatQuantity = 0;
int nHatQuantity = 0;
cout << endl
<< "Hello, and welcome to Books, Bats 'n Hats2.0"
<< endl << endl
<< "1. books"
<< endl << endl
<< "2. bats"
<< endl << endl
<< "3. hats"
<< endl << endl
<< "4. void item(s)"
<< endl << endl
<< "5. checkout"
<< endl << endl
<< "6. exit"
<< endl << endl;
while(true){
int nVoidNumber;
int nValue;
cout << "Please make a selection: ";
cin >> nValue;
switch(nValue)
{
case 1:
cout << "Please enter a quantity of books to purchase: ";
cin >> nBookQuantity;
continue;
case 2:
cout << "Please enter a quantity of bats to purchase: ";
cin >> nBatQuantity;
continue;
case 3:
cout << "Please enter a quantity of hats to purchase: ";
cin >> nHatQuantity;
continue;
case 4:
cout << endl << endl
<< "(1) book(s)"
<< "(2) bat(s)"
<< "(3) hat(s)"
<< "(4) cancel"
<< "Please select an item number to void items: ";
cin >> nVoidNumber;
switch(nVoidNumber)
{
case 1:
nBookQuantity = 0;
cout << "the books are Voided!";
break;
case 2:
nBatQuantity = 0;
cout << "the bats are Voided!";
break;
case 3:
nHatQuantity = 0;
cout << "the hats are Voided!";
break;
case 4:
cout << "cancelling...";
break;
}
continue;
case 5:
cout << endl
<< "Welcome to the checkout! -- Books, Bats 'n Hats2.0"
<< endl << endl
<< "book(s): " << nBookQuantity << endl
<< "bat(s): " << nBatQuantity << endl
<< "hat(s): " << nHatQuantity
<< endl;
cout << "To checkout, enter 'y'. To continue shopping, enter 'n'. Please make a selection: ";
char cCheckoutChoice;
cin >> cCheckoutChoice;
if(cCheckoutChoice = 'y'){
cout << "Thankyou for shopping at Books, Bats 'n Hats. Please come again!";
break;
}if(cCheckoutChoice = 'n'){
continue;
}else{
cout << "command not understood - continuing...";
continue;
}
case 6:
cout << endl
<< "Thank you for visiting Books, Bats 'n Hats2.0"
<< endl;
break;
}
break;
}
返回0;
}