• C

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;
      }
}
nix112Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RodneyYeoCommented:
I copied your codes and tested it...unless you are careless in copying your codes to this forum, you forgot last close braces for your main() function.

And try using
void main() or int main()

for int main()..remember to put return a value

Besides that your codes seems to work perfectly fine unless I missed out something.

P.s You might want to take out your      
         printf("Enter the price:");
         scanf("%d", &price);
and put it before the switch(..)
Less code to write :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nix112Author Commented:
Thanks alot! Got it working.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.