im trying a code to calculate accumulated/incremented amount of specific value.
for (int a=1; a<= qtydrink; a++)
{
cout << "enter drink name:"
cin.getline( drink, 15)
.......
if (strcmp(drink, "beer") == 0)
{
payment = 10.00;
.......
oke so one beer would cost 10$, but if the user input another beer, will it add or replace or something? i have an amount of 1.20 and user inputs it twice, amounting to 2.40 but in the output its just 2.20 sometimes.
i have 2 for loops. one for food and one for drinks. each time user can input different types of foods or drinks with different payments. i have to total up both food and drink's payment in the end plus tax.
please elaborate.
On the assumption that you are using payment
as your output, that would be because you are setting the payment to be equal to 10.00, rather than incrementing it. To perform the increment, use +=
instead of =
EDIT: Everything you need to know about operators can be found here