I want the Total to add the previous total to the new total when the user decides to order another order. The output that i'm getting is this:
Enter order: 022
Quantity: 1
Total: 80
Additional Order (y/n):y
Enter order: 022
Quantity: 1
Total: 80
Additional Order (y/n):n
But i want it like this:
Enter order: 022
Quantity: 1
Total: 80
Additional Order (y/n):y
Enter order: 022
Quantity: 1
Total: 160 <<<<<<<<<<<<<< It added the previous Total to the new order
Additional Order (y/n):n
Help pls.
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cmath>
#include <locale>
void displayTakeOrder(void);
main()
{
system("CLS");
displayTakeOrder();
system("Pause");
system("CLS");
}
void displayTakeOrder(void)
{
char dec = 'y';
while (dec == 'y')
{
int repeat, order,quantity,price;
printf("Entry Order: ");
scanf("%d",&order);
printf("\nQuantity: ");
scanf("%d",&quantity);
if (order == 11)
{
price = 20;
}
else if (order == 22)
{
price = 80;
}
else if (order == 33)
{
price = 85;
}
else if (order == 44)
{
price = 90;
}
else if (order == 55)
{
price = 90;
}
else if (order == 66)
{
price = 150;
}
else if (order == 77)
{
price = 100;
}
else if (order == 88)
{
price = 120;
}
else if (order == 99)
{
price = 130;
}
else if (order == 100)
{
price = 120;
}
else
{
price = 0;
}
int total = (price*quantity);
int total1 = 0;
total1 = total1 + total;
printf("\nTotal: %d",total1);
printf("\n\nAdditional Order?(Press y or n): ");
scanf("%s",&dec);
}
}
Aucun commentaire:
Enregistrer un commentaire