0

hi, can you help me with my code? actually its running but the total price of products bought is not displaying, can you help me with this one? :(

#include<stdio.h>
#include<string.h>
#include<conio.h>
int main(void)
{
      int pno, choice, product, jf=12,d=10,l=107,c=2,cf=22,n=9,b=19,ap,a,total,disc,i,ctr,nSelection;
      char name[50]; char cname[50]; char y; char x;
      float price,qty,tax,dis,bill,dprice,ttotal;
      printf("\n\tMINI SUPER MARKET BILLING SYSTEM");
      printf("\tMADE BY : NICKSON GIL\n");
      printf("\t \t \t \t \tEnjoy :)");
      printf("\n \n \n \t<1> Credit Card  <2> Cash");
      printf("\n \n \t \tPlease Choose the type of Payment : ");
      scanf("%d", &choice);
      switch(choice){
      case 1:
           printf("\n \tCredit Card Payment");
           break;          
           case 2:
           printf("\n \tCash Payment");
           break;
           default:
           {
                           printf("The Program will be terminated");
                           return 0;
                           }
              }
      {
      y:
      printf("\n \tCHOOSE A PRODUCT: ");
      printf("\n<1> Junk Food  <2> Diapers  <3> Liquors <4> Condiments\n<5> Can Foods  <6> Noodles  <7> Beverages :");
      scanf("%d", &product);
      switch(product){
                      case 1:
                           printf("\n \tHow Many? : ");
                           scanf("\n \t%d", &a);
                           i=a*jf;
                           printf("\n \tPrice: %d", i);
                           break;
                      case 2:
                           printf("\n \tHow Many? : ");
                           scanf("\n \t%d", &a);
                           i=d*a;
                           printf("\n \tPrice: %d", i);
                           break;
                      case 3:
                           printf("\n \tHow Many? : ");
                           scanf("\n \t%d", &a);
                           i=l*a;
                           printf("\n \tPrice: %d", i);
                           break;
                      case 4:
                           printf("\n \tHow Many? : ");
                           scanf("%\n \td", &a);
                           i=c*a;
                           printf("\n \tPrice: %d", i);
                           break;
                      case 5:
                           printf("\n \tHow Many? : ");
                           scanf("\n \t%d", &a);
                           i=cf*a;
                           printf("\n \tPrice: %d", i);
                           break;
                      case 6:
                           printf("\n \tHow Many? : ");
                           scanf("\n \t%d", &a);
                           i=n*a;
                           printf("\n \tPrice: %d", i);
                           break;
                      case 7:
                           printf("\n \tHow Many? : ");
                           scanf("%d", &a);
                           i=b*a;
                           printf("\n \tPrice: %d", i);
                           break;
                           default:
                           {
                           printf("The Program will be terminated");
                           return 0;
                           }
                           }
                           printf("\n \tAnother Product? <1> Yes <2> No :");
                           scanf("%d", &ap);
                           if(ap==1)
                           goto y;
                           else if(ap==2)
                           goto n;
                           else if(ap>2)
                           {
                           printf("The Program will be terminated");
                           return 0;
                           }
                           else if(ap=0)
                           {
                           printf("The Program will be terminated");
                           return 0;
                           }
      n:

      printf("\tPlease Enter the Discount (%%) :");
      scanf("%f", &dis);
      disc=dis/100;
      printf("\n\tDiscount :%.2f%%",dis);
      printf("\n\tTotal: %d", i);
      dprice=ttotal/dis;
      printf("\n\tDiscount Exemption: %.2f", dprice);
      bill=ttotal-dprice;
      printf("Total Bill: %.2f", bill);
      }
      getch();
      }                  

Edited by gil.nickson: wrong code

5
Contributors
6
Replies
61
Views
4 Years
Discussion Span
Last Post by noah_2
0

Where in your code is the cost of something added to the total?

Also, it is a very bad idea to control program flow using goto. We have functions and control statements for that.

0

You're not tracking the previous total at all, in each case you're destroying it (i = ...). Have some temporary variable to hold the current transaction total and then add that to the overall total.

Also, main should be declared as follows:
int main (int argc, char** argv)

If it were me, I'd completely trash the usage of the "goto" statements and replace them with do/while loops.

0

Try this:

 }
 ttotal += i;
printf("\n \tAnother Product? <1> Yes <2> No :");
scanf("%d", &ap);
if(ap==1)
goto y;
else if(ap==2)
goto n;
else if(ap>2)
{
printf("The Program will be terminated");
return 0;
}
else if(ap=0)
{
printf("The Program will be terminated");
return 0;
}
n:
printf("\tPlease Enter the Discount (%%) :");
scanf("%f", &dis);
disc=dis/100;
printf("\n\tDiscount :%.2f%%",dis);
printf("\n\tTotal: %d", ttotal);
dprice=ttotal*disc;
printf("\n\tDiscount Exemption: %.2f", dprice);
bill=ttotal-dprice;
printf("Total Bill: %.2f", bill);
}
getch();
} 

You might also want to look at using a while loop, it might look like this:

ap = 1;
ttotal = 0;
while(ap == 1)
{
    printf("\n \tCHOOSE A PRODUCT: ");
    printf("\n<1> Junk Food <2> Diapers <3> Liquors <4> Condiments\n<5> Can Foods <6> Noodles <7> Beverages :");
    scanf("%d", &product);
        switch(product){
        case 1:
            printf("\n \tHow Many? : ");
            scanf("\n \t%d", &a);
            i=a*jf;
            printf("\n \tPrice: %d", i);
            break;
        case 2:
            printf("\n \tHow Many? : ");
            scanf("\n \t%d", &a);
            i=d*a;
            printf("\n \tPrice: %d", i);
            break;
        case 3:
            printf("\n \tHow Many? : ");
            scanf("\n \t%d", &a);
            i=l*a;
            printf("\n \tPrice: %d", i);
            break;
        case 4:
            printf("\n \tHow Many? : ");
            scanf("%\n \td", &a);
            i=c*a;
            printf("\n \tPrice: %d", i);
            break;
        case 5:
            printf("\n \tHow Many? : ");
            scanf("\n \t%d", &a);
            i=cf*a;
            printf("\n \tPrice: %d", i);
            break;
        case 6:
            printf("\n \tHow Many? : ");
            scanf("\n \t%d", &a);
            i=n*a;
            printf("\n \tPrice: %d", i);
            break;
        case 7:
            printf("\n \tHow Many? : ");
            scanf("%d", &a);
            i=b*a;
            printf("\n \tPrice: %d", i);
            break;
        default:
        {
            printf("The Program will be terminated");
            return 0;
        }
    }
    ttotal += i;
    printf("\n \tAnother Product? <1> Yes <2> No :");
    scanf("%d", &ap);
    if(ap>2 || ap == 0)
    {
    printf("The Program will be terminated");
    return 0;
    }


}   
printf("\tPlease Enter the Discount (%%) :");
scanf("%f", &dis);
disc=dis/100;
printf("\n\tDiscount :%.2f%%",dis);
printf("\n\tTotal: %d", ttotal);
dprice=ttotal * disc;
printf("\n\tDiscount Exemption: %.2f", dprice);
bill=ttotal-dprice;
printf("Total Bill: %.2f", bill);
getch();
} 

Edited by tinstaafl

-3

This is just awful

Votes + Comments
It would be helpful if you quoted what you think is awful and suggested ways to improve it.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.