?
Solved

Simple C programming question.

Posted on 1999-11-09
2
Medium Priority
?
248 Views
Last Modified: 2010-05-18
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;
      }
}
0
Comment
Question by:nix112
2 Comments
 

Accepted Solution

by:
RodneyYeo earned 200 total points
ID: 2195905
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
 

Author Comment

by:nix112
ID: 2196084
Thanks alot! Got it working.
0

Featured Post

Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question