so this is a checkout program. Hers my problem: the user enters 1 to enter checkout and then enters the PLU code followed by the weight of it or unit, then they have to choice to enter another PLU code or 0 to exit. Once the user enters 0 it displays the total cost and is suppose to then asks the user again to press 1 to checkout or 0 to exit,instead, it asks to enter the PLU code or 0 to exit. any thoughts on how i can fix this?
You have one loop on 49 and another loop on 61. On line 66, you ask the user to input 0 in order to exit. You exit the "61 loop" on line 72 and end up back in the "49 loop". You need to have some other piece of code that will allow you to exit from the "49 loop" based on user input.
This would be the basic outline of how the program would look if I did it:
int main()
{
//variable declarations
bool codeFound;
bool checkout = true;
//input from file
//prompt user
cin >> userChoice;
if (userChoice == 0)
return 0;
while (checkout)
{
codeFound = false;
while (!codeFound && checkout) //my professor keeps telling me using break is bad practice
{
//prompt user for code or 0 to exit
cin >> code;
if (code == 0)
checkout = false;
else
//search array for code and update codeFound
if (!codeFound && checkout)
//tell user code wasn't found, try again
}
if (checkout)
{
//prompt user for units
cin >> units;
//calculate sum, you used '+' instead of '*' in your code
}
}
//display sum
return 0;
}
what? That doesn't even make sense. You want to tell the user to enter '0' to exit and then tell them again to enter 0 to exit? What do you really want to do?