nix112
asked on
Simple C programming question.
What am i doing wrong with switches here? The errors i get are compound statement missing (but i have it there) and function must return a value (How do i do this?) here is the code. Thanks in advance.
#include <stdio.h>
#include <conio.h>
int discount;
int quantity;
int price;
int gst;
int pst;
int total;
int disprice;
main()
{
printf("\nPress 1 ---> for a quantity of 1.");
printf("\nPress 2 ---> for a quantity of 2.");
printf("\nPress 3 ---> for a quantity of 3.");
printf("\nPress 4 ---> for a quantity of 4+.");
scanf("%d", &quantity);
switch (quantity)
{
case 1:
{
printf("Enter the price:");
scanf("%d", &price);
gst=price+7%-price;
pst=price+7%-price;
total=price+gst+pst;
printf("Quantity = %d", quantity);
printf("GST = %d", gst);
printf("PST = %d", pst);
printf("Total = %d", total);
break;
}
case 2:
{
printf("Enter the price:");
scanf("%d", &price);
discount=price+5%-price;
disprice=price-discount;
gst=disprice+7%-disprice;
pst=disprice+7%-disprice;
total=disprice+gst+pst;
printf("Quantity = %d", quantity);
printf("Discount = %d", discount);
printf("GST = %d", gst);
printf("PST = %d", pst);
printf("Total = %d", total);
break;
}
case 3:
{
printf("Enter the price:");
scanf("%d", &price);
discount=price+10%-price;
disprice=price-discount;
gst=disprice+7%-disprice;
pst=disprice+7%-disprice;
total=disprice+gst+pst;
printf("Quantity = %d", quantity);
printf("Discount = %d", discount);
printf("GST = %d", gst);
printf("PST = %d", pst);
printf("Total = %d", total);
break;
}
case 4:
{
printf("Enter the price:");
scanf("%d", &price);
discount=price+15%-price;
disprice=price-discount;
gst=disprice+7%-disprice;
pst=disprice+7%-disprice;
total=disprice+gst+pst;
printf("Quantity = %d", quantity);
printf("Discount = %d", discount);
printf("GST = %d", gst);
printf("PST = %d", pst);
printf("Total = %d", total);
break;
}
}
#include <stdio.h>
#include <conio.h>
int discount;
int quantity;
int price;
int gst;
int pst;
int total;
int disprice;
main()
{
printf("\nPress 1 ---> for a quantity of 1.");
printf("\nPress 2 ---> for a quantity of 2.");
printf("\nPress 3 ---> for a quantity of 3.");
printf("\nPress 4 ---> for a quantity of 4+.");
scanf("%d", &quantity);
switch (quantity)
{
case 1:
{
printf("Enter the price:");
scanf("%d", &price);
gst=price+7%-price;
pst=price+7%-price;
total=price+gst+pst;
printf("Quantity = %d", quantity);
printf("GST = %d", gst);
printf("PST = %d", pst);
printf("Total = %d", total);
break;
}
case 2:
{
printf("Enter the price:");
scanf("%d", &price);
discount=price+5%-price;
disprice=price-discount;
gst=disprice+7%-disprice;
pst=disprice+7%-disprice;
total=disprice+gst+pst;
printf("Quantity = %d", quantity);
printf("Discount = %d", discount);
printf("GST = %d", gst);
printf("PST = %d", pst);
printf("Total = %d", total);
break;
}
case 3:
{
printf("Enter the price:");
scanf("%d", &price);
discount=price+10%-price;
disprice=price-discount;
gst=disprice+7%-disprice;
pst=disprice+7%-disprice;
total=disprice+gst+pst;
printf("Quantity = %d", quantity);
printf("Discount = %d", discount);
printf("GST = %d", gst);
printf("PST = %d", pst);
printf("Total = %d", total);
break;
}
case 4:
{
printf("Enter the price:");
scanf("%d", &price);
discount=price+15%-price;
disprice=price-discount;
gst=disprice+7%-disprice;
pst=disprice+7%-disprice;
total=disprice+gst+pst;
printf("Quantity = %d", quantity);
printf("Discount = %d", discount);
printf("GST = %d", gst);
printf("PST = %d", pst);
printf("Total = %d", total);
break;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER