Hi guys! I'm making a program for point of sales. Will you please help me? I want my program to display another transaction when the user type T. If the user input yes, the program will display another transaction. If no, the program will terminate. Any help/suggestions will be appreciated.
Firstly, you can't store letters in an int or a float. You should use char for userchoice, and T_answer. I also don't see where int T is used in your code.
Next, you have total = total += 10.00; in each of your if statements. That's a bit redundant. Total += will add the value and then set it. so using total = total + 10.00; and total += 10.00; are functionally the same.
Also, you're missing an opening bracket
1 2 3 4
if (userchoice == 2)
total = total += 10.00;
}
Finally, I would change the last few lines of your code. Set your while loop to while(T_answer != 'N' && T_answer != 'n')
This way your while loop will continue to run until the user chooses N on the final question. That will allow you to clean the end of your code a bit like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
if (userchoice == '8')
{
orangeshake++;
total += 12.00;
}
if (userchoice == 'T' || userchoice == 't')
{
cout << "\n\n Thank you for shopping\n\n";
cout << "Do you want another transaction? Y/N\n";
cin >> T_answer;
}
if (T_answer == 'N' || T_answer == 'n')
{
cout << "Thank you for shopping!";
return 0;
}
I included the userchoice option for orangeshake to show how I would program those statements to look.
When you type a reply on the very right side of the text box it says Format:
when you click it you get {code}{/code} except in brackets []. Put your code between the two and it'll post your code in an easier to read format as shown:
Try replacing all of your total = total + //price with total += //price and see if that solves it.
Also, you shouldn't need any of the code for if the user answers y to make another transaction. If the user answers n, the code exits the loop, but if they answer y it should just loop back through.