A few months ago, I made a sample point of sale system in C++. Now that I have learnt more about C++, I have tried to make a better copy of it. I am however not getting the behavior from the ifStatement that I am using in the 'checkout' part of the program. What I want is for the program to exit if the user enters 'y', and for it to return to the main menu with any other input. It is however just exiting with any input. I am still fairly new to C++ and don't understand why. Any help would be appreciated. I have included the code in this posting.
#include <iostream>
include
include
using namespace std;
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;
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire