Thread: How to call items to print receipt

  1. #1
    Registered User
    Join Date
    Apr 2020
    Posts
    8

    Unhappy How to call items to print receipt

    Hi, I dont know how to do this part and according to all posts and codes I read, the code does not store how many I've ordered, and it just shows the total price.

    The end goal is to be able to print the individual orders, quantity, and price then its total.
    It would look like this:

    Order Quantity Price

    Breakfast Burrito 2 460

    Blueberry Pancakes 1 180

    Total 640

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <conio.h>
    
    
     
    //void (for menu) declarations
    void Menu (void);
    void Options (void);
    void TakeOrder (void);
    void OptionsGoingToReceipt (void);
    void Receipt (void);
    
    
    
    
    int trial;
    int OptionCode, MenuCode;
    int OptionReceipt;
    
    
      //declaration for quantity
    int quantity;
    
    
      //declaration for price
    float price;
    float TotalPrice;
    float SubTotal;
     
    //main program
    int main ()
    {
        
        //username+password
        
        char username[20];
        char password[20];
    
    
        InputUsernamePasswordAgain: //for goto 
        
        
        
        printf("\n*************************************");
        printf("\nEnter your username: ");
        scanf("%s",username);
     
        printf("***********************************");
        printf("\nEnter your password: ");
        scanf("%s",password);
        
        
     
        if( strcmp ( username,"yeeted" ) == 0 && strcmp ( password,"animo" ) == 0 )
    	{
    	    printf("***********************************");
        	printf("\nWelcome back! You are now logged in! ");
        	printf("\n*************************************");
        	printf("\n\n----------------------------------------------------------------------------------------");
            printf ("\n                         Welcome to Sunny Breakfast Hub!");
            printf ("\n                                Established 2020");
            printf("\n----------------------------------------------------------------------------------------");
        Menu ();
        Options ();
        }
      
      
      else if( strcmp( username,"deleted") == 0 && strcmp ( password,"animo") == 0 )
    	{
        	printf("***********************************");
        	printf("\nWelcome back! You are now logged in! ");
        	printf("\n*************************************");
        	printf("\n\n----------------------------------------------------------------------------------------");
            printf ("\n                         Welcome to Sunny Breakfast Hub!");
            printf ("\n                                Established 2020");
            printf("\n----------------------------------------------------------------------------------------");
            Menu ();
            Options ();
        }
        
      
      else if( strcmp (username,"dlsu") == 0 && strcmp (password,"animo") == 0)
    	{
        	printf("***********************************");
        	printf("\nWelcome back! You are now logged in! ");
        	printf("\n*************************************");
        	printf("\n\n----------------------------------------------------------------------------------------");
            printf ("\n                         Welcome to Sunny Breakfast Hub!");
            printf ("\n                                Established 2020");
            printf("\n----------------------------------------------------------------------------------------");
            Menu ();
            Options ();
        }
      
      
      
      else
        {
        printf("***********************************");
        printf("\nUsername or Password is incorrect!");
        printf("\nPlease try again! ");
    
    
            goto InputUsernamePasswordAgain;
        }
     
    }
     
    
    
    //void function for MENU
    void Menu (void)
    {
     
    printf("\n\n========================================================================================");
    printf ("\n\t                    SUNNY BREAKFAST HUB MENU");
    printf("\n========================================================================================");
    
    
    printf
        ("\n\n    ~~~~~~~~~~~~~~~~~~~~~~                         ~~~~~~~~~~~~~~~~~~");
    
    
    printf
        ("\n     SUNNY BREAKFAST COMBOS                            ALL DAY SANDWICH");
        
    printf
        ("\n    ~~~~~~~~~~~~~~~~~~~~~~                         ~~~~~~~~~~~~~~~~~~");
     
     
    printf
        ("\n\n101    Chicken 'n Waffles       P280            201    Honey Glazed Ham     P200");
     
     
    printf
        ("\n102    Breakfast Burrito        P230            202    Tuna Mayo            P200");
     
     
    printf
        ("\n103    All American Platter     P400            203    Chicken 'n Cheese    P180");
     
     
    printf
        ("\n104    Bacon Maniac w/ Eggs     P300            204    Steak 'n Cheese      P250");
     
     
    printf
        ("\n105    Classic Eggs Benedict    P250            205    Vegan Delight        P150");
     
     
    printf ("\n106    Sausage Maniac w/ Eggs   P300");
     
     
    printf ("\n107    Fiesta Omelette          P250");
     
     
    printf
        ("\n\n   ~~~~~~~~~~~~~~~~~~~~~~                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        
    printf
        ("\n     GOOD MORNING PANCAKES                       SUNNY COFFEE AND REFRESHMENTS");
        
    printf
        ("\n   ~~~~~~~~~~~~~~~~~~~~~~                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
     
     
    printf
        ("\n\n301    Mixed Berries    P180                    401    Vanilla Milkshake    P120");
     
     
    printf
        ("\n302    Blueberry        P180                    402    Cappucino            P120");
     
     
    printf
        ("\n303    Chocolate Chip   P150                    403    Mocha Frappucino     P100");
     
     
    printf
        ("\n304    Banana Walnut    P150                    404    Fresh Orange Juice   P80");
    
    
     
    }
     
     
     
    //void function for OPTIONS
    void Options (void)
    {
     
     
      do
       
        {
         
    printf("\n\n========================================================================================");
    printf ("\n\t                    SUNNY BREAKFAST HUB OPTIONS");
    printf("\n========================================================================================");
    
    
    printf ("\n\n01    Back to Menu ");
    printf ("\n02    Take Order");
    printf ("\n03    Exit Program");
    printf ("\n\nEnter the Option Code here: ");
    scanf ("%i", &OptionCode);
    
    
    //while code (if option code is not in between 1-3)     
    while (OptionCode < 01 || OptionCode > 03)
    {
        
    printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    printf("\n *** Oops! The Option Code entered is not in the choices. Please try again: ");
    scanf ("%i", &OptionCode);
    }
         
     
    switch (OptionCode)
    
    
    {
    
    
     
    case 01:
            Menu ();
            Options ();
    
    
    case 02:
            TakeOrder ();
    
    
    case 03:
            exit (0);
            
    }
       
     
    }
     while (OptionCode < 01 || OptionCode > 03);
     
     
    printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    printf("\n *** Oops! The Option Code entered is not in the choices. Please try again: ");
    scanf ("%i", &OptionCode);
    
    
    }
    
    
    
    
     
    //void function for TakeOrder
    void TakeOrder (void)
    {
     
      do
        {
         
     
    printf("\n========================================================================================");
    printf ("\n\t           Welcome to Sunny Breakfast Hub's Order Section!");
    printf("\n========================================================================================");
    
    
    printf ("\n\nPlease input the Menu Code of your order: ");
    scanf ("%i", &MenuCode);
    
    
         
    switch (MenuCode)
    
    
    {
     
     
       //Breakfast Combos
    case 101:   printf("You ordered: Chicken 'n Waffles");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 280;
                break;
    
    
     
    case 102:   printf("You ordered: Breakfast Burrito");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 230;
                break;
    
    
     
    case 103:   printf("You ordered: All American Platter");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 400;
                break;
    
    
     
    case 104:   printf("You ordered: Bacon Maniac w/ Eggs");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 300;
                break;
    
    
     
    case 105:   printf("You ordered: Classic Eggs Benedict");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 250;
                break;
    
    
     
    case 106:   printf("You ordered: Sausage Manic w/ Eggs");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 300;
                break;
    
    
     
    case 107:   printf("You ordered: Fiesta Omelette");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 250;
                break;
     
     
     
       //All day sandwich
    case 201:   printf("You ordered: Honey Glazed Ham Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 200;
                break;
    
    
     
    case 202:   printf("You ordered: Tuna Mayo Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 200;
                break;
    
    
     
    case 203:   printf("You ordered: Chicken 'n Cheese Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 180;
                break;
    
    
     
    case 204:   printf("You ordered: Steak 'n Cheese Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 250;
                break;
    
    
     
    case 205:   printf("You ordered: Vegan Delight Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 150;
                break;
     
     
     
       //Good Morning Pancakes
    case 301:   printf("You ordered: Mixed Berry Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 180;
                break;
    
    
     
    case 302:   printf("You ordered: Blueberry Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 180;
                break;
    
    
     
    case 303:   printf("You ordered: Chocolate Chip Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 150;
                break;
    
    
     
    case 304:   printf("You ordered: Banana Walnut Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 150;
                break;
     
     
     
       //Sunny Coffee and Refreshments
    case 401:   printf("You ordered: Vanilla Milkshake");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 120;
                break;
    
    
     
    case 402:   printf("You ordered: Cappucino");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 120;
                break;
    
    
     
    case 403: printf("You ordered: Mocha Frappucino");
              printf ("\nQuantity: ");
              scanf ("%d", &quantity);
              price = 100;
              break;
    
    
     
    case 404:   printf("You ordered: Fresh Orange Juice");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 80;
                break;
    
    
     
    }
         
    SubTotal = price * quantity;
         
    TotalPrice += SubTotal;
         
    printf ("\nSubtotal: P%.2f", price);
    
    
    printf (" * %i", quantity);
         
    printf (" = P%.2f", SubTotal);
         
    printf ("\n\nDo you want to purchase more?");
    printf ("\n -> Press (1) if you want to purchase more.");
    printf ("\n -> Press (0) if you want to proceed to checkout options.");
    
    
    printf ("\n\nPlease enter (1/0) here: ");
    scanf ("%i", &trial);
       
    }
     while (trial == 1);
     
    
    
    
    
    OptionsGoingToReceipt ();
     
    }
    
    
    
    
    
    
    
    
    //void optionsgoingtoreceipt
    void OptionsGoingToReceipt (void)
    {
     
     startoptionsreceipt:    //goto starting point
    printf("\n========================================================================================"); 
    printf ("\n\t                 SUNNY BREAKFAST HUB CHECKOUT OPTIONS");
    printf("\n========================================================================================");
    
    
    printf ("\n\n >>> Your Total Bill is: P%.2f", TotalPrice);
    
    
    printf ("\n\n10    Summary of your order (Show Receipt) ");
    printf ("\n20    Back to Sunny Breakfast Hub Options ");
    printf ("\n30    Exit Program");
    printf("\n\n========================================================================================");
    printf ("\n\nEnter the option number here: ");
    scanf ("%d", &OptionReceipt);
    
    
        if (OptionReceipt == 10)
        {
            Receipt ();
        }
        
        
        else if (OptionReceipt == 20)
        {
            Options ();
        }
        
        
        else if (OptionReceipt == 30)
        {
            exit (0);
        }
        
        
        else if (OptionReceipt != 10 || OptionReceipt != 20 || OptionReceipt != 30)
            {
            printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            printf("\n * Input error! The Option No. entered is not in the choices. Please try again. *");
            printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
            goto startoptionsreceipt; //repeat void OptionsGoingToReceipt
            }
            
    
    
    }
    
    
    //void Receipt
    void Receipt (void)
    {
        printf ("idk what to do"); ////help pls
    }

  2. #2
    Registered User
    Join Date
    Apr 2020
    Posts
    8
    Any inputs will be appreciated, thanks in advance

  3. #3
    Registered User
    Join Date
    Jan 2020
    Posts
    8
    First of All, your code is amazing. It seems you did put a lot of efforts into it.

    The menu which you printed in print statement could be stored in a multidimensional String array, and can be printed using a loop.
    Here I didn't wanted to do all that storing the menu in an array, that's too hectic.
    What I did is used an array to store the Order.
    It's like a 20 by 3 table, 20 rows as your menu has max 20 items.
    3 columns are for Menu code, quantity, Subtotal respectively.

    Also note that , you didn't put a default condition in Switch statement, if someone enters menu code that doesnot exist then
    it must prompt for for Wrong option and ask for menu code again.

    so here is my code(Honestly it's your's , I just did some changes):

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <conio.h>
    
    
    
    
    
    
    //void (for menu) declarations
    void Menu (void);
    void Options (void);
    void TakeOrder (void);
    void OptionsGoingToReceipt (void);
    void Receipt (void);
    
    
    
    
    
    
    
    
    int trial;
    int OptionCode, MenuCode;
    int OptionReceipt;
    
    
    
    
      //declaration for quantity
    int quantity;
    
    
    
    
      //declaration for price
    float price;
    float TotalPrice;
    float SubTotal;
    
    
    //for receipt data
    int order[20][3],orders=0;
    
    
    //main program
    int main ()
    {
    
    
        //username+password
    
    
        char username[20];
        char password[20];
    
    
    
    
        InputUsernamePasswordAgain: //for goto
    
    
    
    
    
    
        printf("\n*************************************");
        printf("\nEnter your username: ");
        scanf("%s",username);
    
    
        printf("***********************************");
        printf("\nEnter your password: ");
        scanf("%s",password);
    
    
    
    
    
    
        if( strcmp ( username,"yeeted" ) == 0 && strcmp ( password,"animo" ) == 0 )
        {
            printf("***********************************");
            printf("\nWelcome back! You are now logged in! ");
            printf("\n*************************************");
            printf("\n\n----------------------------------------------------------------------------------------");
            printf ("\n                         Welcome to Sunny Breakfast Hub!");
            printf ("\n                                Established 2020");
            printf("\n----------------------------------------------------------------------------------------");
        Menu ();
        Options ();
        }
    
    
    
    
      else if( strcmp( username,"deleted") == 0 && strcmp ( password,"animo") == 0 )
        {
            printf("***********************************");
            printf("\nWelcome back! You are now logged in! ");
            printf("\n*************************************");
            printf("\n\n----------------------------------------------------------------------------------------");
            printf ("\n                         Welcome to Sunny Breakfast Hub!");
            printf ("\n                                Established 2020");
            printf("\n----------------------------------------------------------------------------------------");
            Menu ();
            Options ();
        }
    
    
    
    
      else if( strcmp (username,"dlsu") == 0 && strcmp (password,"animo") == 0)
        {
            printf("***********************************");
            printf("\nWelcome back! You are now logged in! ");
            printf("\n*************************************");
            printf("\n\n----------------------------------------------------------------------------------------");
            printf ("\n                         Welcome to Sunny Breakfast Hub!");
            printf ("\n                                Established 2020");
            printf("\n----------------------------------------------------------------------------------------");
            Menu ();
            Options ();
        }
    
    
    
    
    
    
      else
        {
        printf("***********************************");
        printf("\nUsername or Password is incorrect!");
        printf("\nPlease try again! ");
    
    
    
    
            goto InputUsernamePasswordAgain;
        }
    
    
    }
    
    
    
    
    
    
    //void function for MENU
    void Menu (void)
    {
    
    
    printf("\n\n========================================================================================");
    printf ("\n\t                    SUNNY BREAKFAST HUB MENU");
    printf("\n========================================================================================");
    
    
    
    
    printf
        ("\n\n    ~~~~~~~~~~~~~~~~~~~~~~                         ~~~~~~~~~~~~~~~~~~");
    
    
    
    
    printf
        ("\n     SUNNY BREAKFAST COMBOS                            ALL DAY SANDWICH");
    
    
    printf
        ("\n    ~~~~~~~~~~~~~~~~~~~~~~                         ~~~~~~~~~~~~~~~~~~");
    
    
    
    
    printf
        ("\n\n101    Chicken 'n Waffles       P280            201    Honey Glazed Ham     P200");
    
    
    
    
    printf
        ("\n102    Breakfast Burrito        P230            202    Tuna Mayo            P200");
    
    
    
    
    printf
        ("\n103    All American Platter     P400            203    Chicken 'n Cheese    P180");
    
    
    
    
    printf
        ("\n104    Bacon Maniac w/ Eggs     P300            204    Steak 'n Cheese      P250");
    
    
    
    
    printf
        ("\n105    Classic Eggs Benedict    P250            205    Vegan Delight        P150");
    
    
    
    
    printf ("\n106    Sausage Maniac w/ Eggs   P300");
    
    
    
    
    printf ("\n107    Fiesta Omelette          P250");
    
    
    
    
    printf
        ("\n\n   ~~~~~~~~~~~~~~~~~~~~~~                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    
    
    printf
        ("\n     GOOD MORNING PANCAKES                       SUNNY COFFEE AND REFRESHMENTS");
    
    
    printf
        ("\n   ~~~~~~~~~~~~~~~~~~~~~~                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    
    
    
    
    printf
        ("\n\n301    Mixed Berries    P180                    401    Vanilla Milkshake    P120");
    
    
    
    
    printf
        ("\n302    Blueberry        P180                    402    Cappucino            P120");
    
    
    
    
    printf
        ("\n303    Chocolate Chip   P150                    403    Mocha Frappucino     P100");
    
    
    
    
    printf
        ("\n304    Banana Walnut    P150                    404    Fresh Orange Juice   P80");
    
    
    
    
    
    
    }
    
    
    
    
    
    
    //void function for OPTIONS
    void Options (void)
    {
    
    
    
    
      do
    
    
        {
    
    
    printf("\n\n========================================================================================");
    printf ("\n\t                    SUNNY BREAKFAST HUB OPTIONS");
    printf("\n========================================================================================");
    
    
    
    
    printf ("\n\n01    Back to Menu ");
    printf ("\n02    Take Order");
    printf ("\n03    Exit Program");
    printf ("\n\nEnter the Option Code here: ");
    scanf ("%i", &OptionCode);
    
    
    
    
    //while code (if option code is not in between 1-3)
    while (OptionCode < 01 || OptionCode > 03)
    {
    
    
    printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    printf("\n *** Oops! The Option Code entered is not in the choices. Please try again: ");
    scanf ("%i", &OptionCode);
    }
    
    
    
    
    switch (OptionCode)
    
    
    
    
    {
    
    
    
    
    
    
    case 01:
            Menu ();
            Options ();
    
    
    
    
    case 02:
            TakeOrder ();
    
    
    
    
    case 03:
            exit (0);
    
    
    }
    
    
    
    
    }
     while (OptionCode < 01 || OptionCode > 03);
    
    
    
    
    printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    printf("\n *** Oops! The Option Code entered is not in the choices. Please try again: ");
    scanf ("%i", &OptionCode);
    
    
    
    
    }
    
    
    
    
    
    
    
    
    
    
    //void function for TakeOrder
    void TakeOrder (void)
    {
      TryAgain:
      do
        {
    
    
    
    
    printf("\n========================================================================================");
    printf ("\n\t           Welcome to Sunny Breakfast Hub's Order Section!");
    printf("\n========================================================================================");
    
    
    
    
    printf ("\n\nPlease input the Menu Code of your order: ");
    scanf ("%i", &MenuCode);
    
    
    
    
    
    
    switch (MenuCode)
    
    
    
    
    {
    
    
    
    
       //Breakfast Combos
    case 101:   printf("You ordered: Chicken 'n Waffles");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 280;
                order[orders][0]=101;
                order[orders][1]=quantity;
                order[orders][2]=quantity*280;
                orders++;
                break;
    
    
    
    
    
    
    case 102:   printf("You ordered: Breakfast Burrito");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 230;
                order[orders][0]=102;
                order[orders][1]=quantity;
                order[orders][2]=quantity*230;
                orders++;
                break;
    
    
    
    
    
    
    case 103:   printf("You ordered: All American Platter");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 400;
                order[orders][0]=103;
                order[orders][1]=quantity;
                order[orders][2]=quantity*400;
                orders++;
                break;
    
    
    
    
    
    
    case 104:   printf("You ordered: Bacon Maniac w/ Eggs");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 300;
                order[orders][0]=104;
                order[orders][1]=quantity;
                order[orders][2]=quantity*300;
                orders++;
                break;
    
    
    
    
    
    
    case 105:   printf("You ordered: Classic Eggs Benedict");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 250;
                order[orders][0]=105;
                order[orders][1]=quantity;
                order[orders][2]=quantity*250;
                orders++;
                break;
    
    
    
    
    
    
    case 106:   printf("You ordered: Sausage Manic w/ Eggs");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 300;
                order[orders][0]=106;
                order[orders][1]=quantity;
                order[orders][2]=quantity*300;
                orders++;
                break;
    
    
    
    
    
    
    case 107:   printf("You ordered: Fiesta Omelette");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 250;
                order[orders][0]=107;
                order[orders][1]=quantity;
                order[orders][2]=quantity*250;
                orders++;
                break;
    
    
    
    
    
    
       //All day sandwich
    case 201:   printf("You ordered: Honey Glazed Ham Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 200;
                order[orders][0]=201;
                order[orders][1]=quantity;
                order[orders][2]=quantity*200;
                orders++;
                break;
    
    
    
    
    
    
    case 202:   printf("You ordered: Tuna Mayo Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 200;
                order[orders][0]=202;
                order[orders][1]=quantity;
                order[orders][2]=quantity*200;
                orders++;
                break;
    
    
    
    
    
    
    case 203:   printf("You ordered: Chicken 'n Cheese Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 180;
                order[orders][0]=203;
                order[orders][1]=quantity;
                order[orders][2]=quantity*180;
                orders++;
                break;
    
    
    
    
    
    
    case 204:   printf("You ordered: Steak 'n Cheese Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 250;
                order[orders][0]=204;
                order[orders][1]=quantity;
                order[orders][2]=quantity*250;
                orders++;
                break;
    
    
    
    
    
    
    case 205:   printf("You ordered: Vegan Delight Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 150;
                order[orders][0]=205;
                order[orders][1]=quantity;
                order[orders][2]=quantity*150;
                orders++;
                break;
    
    
    
    
    
    
       //Good Morning Pancakes
    case 301:   printf("You ordered: Mixed Berry Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 180;
                order[orders][0]=301;
                order[orders][1]=quantity;
                order[orders][2]=quantity*180;
                orders++;
                break;
    
    
    
    
    
    
    case 302:   printf("You ordered: Blueberry Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 180;
                order[orders][0]=302;
                order[orders][1]=quantity;
                order[orders][2]=quantity*180;
                orders++;
                break;
    
    
    
    
    
    
    case 303:   printf("You ordered: Chocolate Chip Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 150;
                order[orders][0]=303;
                order[orders][1]=quantity;
                order[orders][2]=quantity*150;
                orders++;
                break;
    
    
    
    
    
    
    case 304:   printf("You ordered: Banana Walnut Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 150;
                order[orders][0]=304;
                order[orders][1]=quantity;
                order[orders][2]=quantity*150;
                orders++;
                break;
    
    
    
    
    
    
       //Sunny Coffee and Refreshments
    case 401:   printf("You ordered: Vanilla Milkshake");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 120;
                order[orders][0]=401;
                order[orders][1]=quantity;
                order[orders][2]=quantity*120;
                orders++;
                break;
    
    
    
    
    
    
    case 402:   printf("You ordered: Cappucino");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 120;
                order[orders][0]=402;
                order[orders][1]=quantity;
                order[orders][2]=quantity*120;
                orders++;
                break;
    
    
    
    
    
    
    case 403: printf("You ordered: Mocha Frappucino");
              printf ("\nQuantity: ");
              scanf ("%d", &quantity);
              price = 100;
              order[orders][0]=403;
              order[orders][1]=quantity;
              order[orders][2]=quantity*100;
              orders++;
              break;
    
    
    
    
    
    
    case 404:   printf("You ordered: Fresh Orange Juice");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 80;
                order[orders][0]=404;
                order[orders][1]=quantity;
                order[orders][2]=quantity*80;
                orders++;
                break;
    
    
    default: printf("You have entered a wrong option.\n Try Again");
             goto TryAgain;
    
    
    }
    
    
    SubTotal = price * quantity;
    
    
    TotalPrice += SubTotal;
    
    
    printf ("\nSubtotal: P%.2f", price);
    
    
    
    
    printf (" * %i", quantity);
    
    
    printf (" = P%.2f", SubTotal);
    
    
    printf ("\n\nDo you want to purchase more?");
    printf ("\n -> Press (1) if you want to purchase more.");
    printf ("\n -> Press (0) if you want to proceed to checkout options.");
    
    
    
    
    printf ("\n\nPlease enter (1/0) here: ");
    scanf ("%i", &trial);
    
    
    }
     while (trial == 1);
    
    
    
    
    
    
    
    
    
    
    OptionsGoingToReceipt ();
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    //void optionsgoingtoreceipt
    void OptionsGoingToReceipt (void)
    {
    
    
     startoptionsreceipt:    //goto starting point
    printf("\n========================================================================================");
    printf ("\n\t                 SUNNY BREAKFAST HUB CHECKOUT OPTIONS");
    printf("\n========================================================================================");
    
    
    
    
    printf ("\n\n >>> Your Total Bill is: P%.2f", TotalPrice);
    
    
    
    
    printf ("\n\n10    Summary of your order (Show Receipt) ");
    printf ("\n20    Back to Sunny Breakfast Hub Options ");
    printf ("\n30    Exit Program");
    printf("\n\n========================================================================================");
    printf ("\n\nEnter the option number here: ");
    scanf ("%d", &OptionReceipt);
    
    
    
    
        if (OptionReceipt == 10)
        {
            Receipt ();
        }
    
    
    
    
        else if (OptionReceipt == 20)
        {
            Options ();
        }
    
    
    
    
        else if (OptionReceipt == 30)
        {
            exit (0);
        }
    
    
    
    
        else if (OptionReceipt != 10 || OptionReceipt != 20 || OptionReceipt != 30)
            {
            printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            printf("\n * Input error! The Option No. entered is not in the choices. Please try again. *");
            printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
            goto startoptionsreceipt; //repeat void OptionsGoingToReceipt
            }
    
    
    
    
    
    
    }
    
    
    
    
    //void Receipt
    void Receipt (void)
    {
        printf("\n========================================================================================");
        printf ("\n\t                 SUNNY BREAKFAST HUB Receipt");
        printf("\n========================================================================================");
        printf("\n   Order\t    Quantity\tPrice\n(Menu Code)\n");
        for(int i=0;i<orders;i++)
            printf("\n   %d\t\t    %d\t\t%d",order[i][0],order[i][1],order[i][2]);
        printf("\n\tTotal Price: %.2f",TotalPrice);
        printf("\n\n========================================================================================");
        printf ("\n\t                 SUNNY BREAKFAST HUB");
        printf ("\n\t                 THANK YOU :-)");
        printf("\n========================================================================================");
    }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,110
    I don't suppose you've come across things like
    - arrays
    - structures
    - loops

    Things that would greatly simplify your code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Aug 2019
    Location
    inside a singularity
    Posts
    302
    > First of All, your code is amazing. It seems you did put a lot of efforts into it.

    Sorry to say but the code is horrible. You probably haven't experienced what good, neat code looks like
    About the efforts: yeah, they are a lot, but not required tbh. This can be made much much much simpler.

    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook, The Wizardry Compiled

  6. #6
    Registered User
    Join Date
    Apr 2020
    Posts
    8
    Hellooo sorry late reply but thanks so much!!! You placed a lot of effort as well. I copied your code but this part had an error so I fixed it already. I read your feedback and learned a lot from it so thanks again, really appreciate it.


    The error:
    Code:
     for(int i=0;i<orders;i++)
    Got fixed though so here:
    Code:
     int i=0;//void Receipt
    void Receipt (void)
    {
        printf("\n========================================================================================");
        printf ("\n\t                 SUNNY BREAKFAST HUB Receipt");
        printf("\n========================================================================================");
        printf("\n   Order\t    Quantity\tPrice\n(Menu Code)\n");
        for( i=0;i<orders;i++)
            printf("\n   %d\t\t    %d\t\t%d",order[i][0],order[i][1],order[i][2]);
        printf("\nTotal Price: %.2f",TotalPrice);
        GoingDiscounts();
    }
    
    
    void GoingDiscounts (void)
    {
    printf ("\n\t                 Would you like a discount?");
    printf ("\n\n001    None ");
    printf ("\n002    Senior (20%)");
    printf ("\n003    Others (30%)");
    InputGoingDiscountsAgain:
    printf ("\n\nEnter the Discount Code here: ");
    scanf ("%i", &discount);
    This is the final output btw:
    Code:
     #include <stdio.h>#include <stdlib.h>
    #include <string.h>
    #include <conio.h>
     
     
     
     
     
     
    //void (for menu) declarations
    void Menu (void);
    void Options (void);
    void TakeOrder (void);
    void OptionsGoingToReceipt (void);
    void Receipt (void);
    void GoingDiscounts (void);
    void Change (void);
     
     
     
     
     
     
     
    int trial;
    int OptionCode, MenuCode;
    int OptionReceipt;
    int discount;
     
     
     
     
      //declaration for quantity
    int quantity;
     
     
     
     
      //declaration for price
    float price;
    float TotalPrice;
    float SubTotal;
    float DiscountPrice;
    float payment;
    float change;
    
    
     
    //for receipt data
    int order[20][3],orders=0;
     
     
    //main program
    int main ()
    {
     
     
        //username+password
     
     
        char username[20];
        char password[20];
     
     
     
     
        InputUsernamePasswordAgain: //for goto
     
     
     
     
     
     
        printf("\n*************************************");
        printf("\nEnter your username: ");
        scanf("%s",username);
     
     
        printf("***********************************");
        printf("\nEnter your password: ");
        scanf("%s",password);
     
     
     
     
     
     
        if( strcmp ( username,"yeeted" ) == 0 && strcmp ( password,"animo" ) == 0 )
        {
            printf("***********************************");
            printf("\nWelcome back! You are now logged in! ");
            printf("\n*************************************");
            printf("\n\n----------------------------------------------------------------------------------------");
            printf ("\n                         Welcome to Sunny Breakfast Hub!");
            printf ("\n                                Established 2020");
            printf("\n----------------------------------------------------------------------------------------");
        Menu ();
        Options ();
        }
     
     
     
      else if( strcmp( username,"deleted") == 0 && strcmp ( password,"animo") == 0 )
        {
            printf("***********************************");
            printf("\nWelcome back! You are now logged in! ");
            printf("\n*************************************");
            printf("\n\n----------------------------------------------------------------------------------------");
            printf ("\n                         Welcome to Sunny Breakfast Hub!");
            printf ("\n                                Established 2020");
            printf("\n----------------------------------------------------------------------------------------");
            Menu ();
            Options ();
        }
     
     
     
     
      else if( strcmp (username,"dlsu") == 0 && strcmp (password,"animo") == 0)
        {
            printf("***********************************");
            printf("\nWelcome back! You are now logged in! ");
            printf("\n*************************************");
            printf("\n\n----------------------------------------------------------------------------------------");
            printf ("\n                         Welcome to Sunny Breakfast Hub!");
            printf ("\n                                Established 2020");
            printf("\n----------------------------------------------------------------------------------------");
            Menu ();
            Options ();
        }
     
     
     
     
     
     
      else
        {
        printf("***********************************");
        printf("\nUsername or Password is incorrect!");
        printf("\nPlease try again! ");
     
     
     
     
            goto InputUsernamePasswordAgain;
        }
     
     
    }
     
     
     
     
     
     
    //void function for MENU
    void Menu (void)
    {
     
     
    printf("\n\n========================================================================================");
    printf ("\n\t                    SUNNY BREAKFAST HUB MENU");
    printf("\n========================================================================================");
     
     
     
     
    printf
        ("\n\n    ~~~~~~~~~~~~~~~~~~~~~~                         ~~~~~~~~~~~~~~~~~~");
     
     
     
     
    printf
        ("\n     SUNNY BREAKFAST COMBOS                            ALL DAY SANDWICH");
     
     
    printf
        ("\n    ~~~~~~~~~~~~~~~~~~~~~~                         ~~~~~~~~~~~~~~~~~~");
     
     
     
     
    printf
        ("\n\n101    Chicken 'n Waffles       P280            201    Honey Glazed Ham     P200");
     
     
     
     
    printf
        ("\n102    Breakfast Burrito        P230            202    Tuna Mayo            P200");
     
     
     
     
    printf
        ("\n103    All American Platter     P400            203    Chicken 'n Cheese    P180");
     
     
     
     
    printf
        ("\n104    Bacon Maniac w/ Eggs     P300            204    Steak 'n Cheese      P250");
     
     
     
     
    printf
        ("\n105    Classic Eggs Benedict    P250            205    Vegan Delight        P150");
     
     
     
     
    printf ("\n106    Sausage Maniac w/ Eggs   P300");
     
     
     
     
    printf ("\n107    Fiesta Omelette          P250");
     
     
     
     
    printf
        ("\n\n   ~~~~~~~~~~~~~~~~~~~~~~                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
     
     
    printf
        ("\n     GOOD MORNING PANCAKES                       SUNNY COFFEE AND REFRESHMENTS");
     
     
    printf
        ("\n   ~~~~~~~~~~~~~~~~~~~~~~                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
     
     
     
     
    printf
        ("\n\n301    Mixed Berries    P180                    401    Vanilla Milkshake    P120");
     
     
     
     
    printf
        ("\n302    Blueberry        P180                    402    Cappucino            P120");
     
     
     
     
    printf
        ("\n303    Chocolate Chip   P150                    403    Mocha Frappucino     P100");
     
     
     
     
    printf
        ("\n304    Banana Walnut    P150                    404    Fresh Orange Juice   P80");
     
     
     
     
     
     
    }
     
     
     
     
     
     
    //void function for OPTIONS
    void Options (void)
    {
     
     
     
     
      do
     
     
        {
     
     
    printf("\n\n========================================================================================");
    printf ("\n\t                    SUNNY BREAKFAST HUB OPTIONS");
    printf("\n========================================================================================");
     
     
     
     
    printf ("\n\n01    Back to Menu ");
    printf ("\n02    Take Order");
    printf ("\n03    Exit Program");
    printf ("\n\nEnter the Option Code here: ");
    scanf ("%i", &OptionCode);
     
     
     
     
    //while code (if option code is not in between 1-3)
    while (OptionCode < 01 || OptionCode > 03)
    {
     
     
    printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    printf("\n *** Oops! The Option Code entered is not in the choices. Please try again: ");
    scanf ("%i", &OptionCode);
    }
     
     
     
     
    switch (OptionCode)
     
     
     
     
    {
     
     
     
     
     
     
    case 01:
            Menu ();
            Options ();
     
     
     
     
    case 02:
            TakeOrder ();
     
     
     
     
    case 03:
            exit (0);
     
     
    }
     
     
     
     
    }
     while (OptionCode < 01 || OptionCode > 03);
     
     
     
     
    printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    printf("\n *** Oops! The Option Code entered is not in the choices. Please try again: ");
    scanf ("%i", &OptionCode);
     
     
     
     
    }
     
     
     
     
     
     
     
     
     
     
    //void function for TakeOrder
    void TakeOrder (void)
    {
      TryAgain:
      do
        {
     
     
     
     
    printf("\n========================================================================================");
    printf ("\n\t           Welcome to Sunny Breakfast Hub's Order Section!");
    printf("\n========================================================================================");
     
     
     
     
    printf ("\n\nPlease input the Menu Code of your order: ");
    scanf ("%i", &MenuCode);
     
     
     
     
     
     
    switch (MenuCode)
     
     
     
     
    {
     
     
     
     
       //Breakfast Combos
    case 101:   printf("You ordered: Chicken 'n Waffles");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 280;
                order[orders][0]=101;
                order[orders][1]=quantity;
                order[orders][2]=quantity*280;
                orders++;
                break;
     
     
     
     
     
     
    case 102:   printf("You ordered: Breakfast Burrito");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 230;
                order[orders][0]=102;
                order[orders][1]=quantity;
                order[orders][2]=quantity*230;
                orders++;
                break;
     
     
     
     
     
     
    case 103:   printf("You ordered: All American Platter");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 400;
                order[orders][0]=103;
                order[orders][1]=quantity;
                order[orders][2]=quantity*400;
                orders++;
                break;
     
     
     
     
     
     
    case 104:   printf("You ordered: Bacon Maniac w/ Eggs");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 300;
                order[orders][0]=104;
                order[orders][1]=quantity;
                order[orders][2]=quantity*300;
                orders++;
                break;
     
     
     
     
     
     
    case 105:   printf("You ordered: Classic Eggs Benedict");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 250;
                order[orders][0]=105;
                order[orders][1]=quantity;
                order[orders][2]=quantity*250;
                orders++;
                break;
     
     
     
     
     
     
    case 106:   printf("You ordered: Sausage Manic w/ Eggs");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 300;
                order[orders][0]=106;
                order[orders][1]=quantity;
                order[orders][2]=quantity*300;
                orders++;
                break;
     
     
     
     
     
     
    case 107:   printf("You ordered: Fiesta Omelette");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 250;
                order[orders][0]=107;
                order[orders][1]=quantity;
                order[orders][2]=quantity*250;
                orders++;
                break;
     
     
     
     
     
     
       //All day sandwich
    case 201:   printf("You ordered: Honey Glazed Ham Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 200;
                order[orders][0]=201;
                order[orders][1]=quantity;
                order[orders][2]=quantity*200;
                orders++;
                break;
     
     
     
     
     
     
    case 202:   printf("You ordered: Tuna Mayo Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 200;
                order[orders][0]=202;
                order[orders][1]=quantity;
                order[orders][2]=quantity*200;
                orders++;
                break;
     
     
     
     
     
     
    case 203:   printf("You ordered: Chicken 'n Cheese Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 180;
                order[orders][0]=203;
                order[orders][1]=quantity;
                order[orders][2]=quantity*180;
                orders++;
                break;
     
     
     
     
     
     
    case 204:   printf("You ordered: Steak 'n Cheese Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 250;
                order[orders][0]=204;
                order[orders][1]=quantity;
                order[orders][2]=quantity*250;
                orders++;
                break;
     
     
     
     
     
     
    case 205:   printf("You ordered: Vegan Delight Sandwich");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 150;
                order[orders][0]=205;
                order[orders][1]=quantity;
                order[orders][2]=quantity*150;
                orders++;
                break;
     
     
     
     
     
     
       //Good Morning Pancakes
    case 301:   printf("You ordered: Mixed Berry Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 180;
                order[orders][0]=301;
                order[orders][1]=quantity;
                order[orders][2]=quantity*180;
                orders++;
                break;
     
     
     
     
     
     
    case 302:   printf("You ordered: Blueberry Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 180;
                order[orders][0]=302;
                order[orders][1]=quantity;
                order[orders][2]=quantity*180;
                orders++;
                break;
     
     
     
     
     
     
    case 303:   printf("You ordered: Chocolate Chip Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 150;
                order[orders][0]=303;
                order[orders][1]=quantity;
                order[orders][2]=quantity*150;
                orders++;
                break;
     
     
     
     
     
     
    case 304:   printf("You ordered: Banana Walnut Pancakes");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 150;
                order[orders][0]=304;
                order[orders][1]=quantity;
                order[orders][2]=quantity*150;
                orders++;
                break;
     
     
     
     
     
     
       //Sunny Coffee and Refreshments
    case 401:   printf("You ordered: Vanilla Milkshake");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 120;
                order[orders][0]=401;
                order[orders][1]=quantity;
                order[orders][2]=quantity*120;
                orders++;
                break;
     
     
     
     
     
     
    case 402:   printf("You ordered: Cappucino");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 120;
                order[orders][0]=402;
                order[orders][1]=quantity;
                order[orders][2]=quantity*120;
                orders++;
                break;
     
     
     
     
     
     
    case 403: printf("You ordered: Mocha Frappucino");
              printf ("\nQuantity: ");
              scanf ("%d", &quantity);
              price = 100;
              order[orders][0]=403;
              order[orders][1]=quantity;
              order[orders][2]=quantity*100;
              orders++;
              break;
     
     
     
     
     
     
    case 404:   printf("You ordered: Fresh Orange Juice");
                printf ("\nQuantity: ");
                scanf ("%d", &quantity);
                price = 80;
                order[orders][0]=404;
                order[orders][1]=quantity;
                order[orders][2]=quantity*80;
                orders++;
                break;
     
     
    default: printf("You have entered a wrong option.\n Try Again");
             goto TryAgain;
     
     
    }
     
     
    SubTotal = price * quantity;
     
     
    TotalPrice += SubTotal;
     
     
    printf ("\nSubtotal: P%.2f", price);
     
     
     
     
    printf (" * %i", quantity);
     
     
    printf (" = P%.2f", SubTotal);
     
     
    printf ("\n\nDo you want to purchase more?");
    printf ("\n -> Press (1) if you want to purchase more.");
    printf ("\n -> Press (0) if you want to proceed to checkout options.");
     
     
     
     
    printf ("\n\nPlease enter (1/0) here: ");
    scanf ("%i", &trial);
     
     
    }
     while (trial == 1);
     
     
     
     
     
     
     
     
     
     
    OptionsGoingToReceipt ();
     
     
    }
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    //void optionsgoingtoreceipt
    void OptionsGoingToReceipt (void)
    {
     
     
     startoptionsreceipt:    //goto starting point
    printf("\n========================================================================================");
    printf ("\n\t                 SUNNY BREAKFAST HUB CHECKOUT OPTIONS");
    printf("\n========================================================================================");
     
     
     
     
    printf ("\n\n >>> Your Total Bill is: P%.2f", TotalPrice);
     
     
     
     
    printf ("\n\n10    Summary of your order (Show Receipt) ");
    printf ("\n20    Back to Sunny Breakfast Hub Options ");
    printf ("\n30    Exit Program");
    printf("\n\n========================================================================================");
    printf ("\n\nEnter the option number here: ");
    scanf ("%d", &OptionReceipt);
     
     
     
     
        if (OptionReceipt == 10)
        {
            Receipt ();
        }
     
     
     
     
        else if (OptionReceipt == 20)
        {
            Options ();
        }
     
     
     
     
        else if (OptionReceipt == 30)
        {
            exit (0);
        }
     
     
     
     
        else if (OptionReceipt != 10 || OptionReceipt != 20 || OptionReceipt != 30)
            {
            printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            printf("\n * Input error! The Option No. entered is not in the choices. Please try again. *");
            printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
            goto startoptionsreceipt; //repeat void OptionsGoingToReceipt
            }
     
     
     
     
     
     
    }
     
     
     
     
    
    
    int i=0;
    //void Receipt
    void Receipt (void)
    {
        printf("\n========================================================================================");
        printf ("\n\t                 SUNNY BREAKFAST HUB Receipt");
        printf("\n========================================================================================");
        printf("\n   Order\t    Quantity\tPrice\n(Menu Code)\n");
        for( i=0;i<orders;i++)
            printf("\n   %d\t\t    %d\t\t%d",order[i][0],order[i][1],order[i][2]);
        printf("\nTotal Price: %.2f",TotalPrice);
        GoingDiscounts();
    }
    
    
    void GoingDiscounts (void)
    {
    printf ("\n\t                 Would you like a discount?");
    printf ("\n\n001    None ");
    printf ("\n002    Senior (20%)");
    printf ("\n003    Others (30%)");
    InputGoingDiscountsAgain:
    printf ("\n\nEnter the Discount Code here: ");
    scanf ("%i", &discount);
    
    
    
    
    if (discount == 001)
        {
            DiscountPrice = TotalPrice;
            Change();
        }
     
     
     
     
        else if (discount == 002)
        {
            DiscountPrice = TotalPrice-(TotalPrice*0.2);
    		Change();
        }
     
     
     
     
        else if (discount == 003)
        {
            DiscountPrice = TotalPrice-(TotalPrice*0.3);
            Change();
    
    
        }
     
     
     
     
        else if (OptionReceipt != 001 || OptionReceipt != 002 || OptionReceipt != 003)
            {
            printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
            printf("\n * Input error! The Discount No. entered is not in the choices. Please try again. *");
            printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
            goto InputGoingDiscountsAgain; //repeat void GoingDiscounts
            }
    
    
    }
    
    
    void Change (void)
    {
    printf ("\nHow much is your payment?");
    printf ("\n\nEnter your payment here: ");
    scanf ("%f",&payment);
    change = payment - DiscountPrice;
    printf ("\nYour payment is: %.2f",payment);
    printf ("\nYour discounted price is: %.2f",DiscountPrice);
    printf ("\nYour change is: %.2f",change);
    printf("\n\n========================================================================================");
      printf ("\n\t                 SUNNY BREAKFAST HUB");
    printf ("\n\t                 THANK YOU :-)");
      printf("\n========================================================================================");
    }

  7. #7
    Registered User
    Join Date
    Apr 2020
    Posts
    8
    Quote Originally Posted by Salem View Post
    I don't suppose you've come across things like
    - arrays
    - structures
    - loops

    Things that would greatly simplify your code.
    Thanks for the input, I dont know much in arrays and structures, but will try to understand how they work.

  8. #8
    Registered User
    Join Date
    Apr 2020
    Posts
    8
    Quote Originally Posted by Zeus_ View Post
    > First of All, your code is amazing. It seems you did put a lot of efforts into it.

    Sorry to say but the code is horrible. You probably haven't experienced what good, neat code looks like
    About the efforts: yeah, they are a lot, but not required tbh. This can be made much much much simpler.

    Well for sure there is a better way but hopefully I get to learn more, thanks.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,110
    Some points to bear in mind.

    1. By convention (and because that's how it works), newlines go at the end of the string being output, not at the start.
    This is because when stdout is a terminal, the stream is typically line buffered, which means it gets flushed with every \n
    In short, printf("hello\n") has a much better chance of being seen than printf("\nhello").

    2. else if (OptionReceipt != 001 || OptionReceipt != 002 || OptionReceipt != 003)
    Beware that numeric constants with a leading zero indicate base 8 (octal) to the compiler, not base 10.
    You're fine up to 007 (Mr Bond), but try writing 008 and you're in for surprises.

    Oh, and before you copy/paste your way to another 1000 line program, here is something to study, and hopefully inspire you.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    struct {
      const char *username;
      const char *password;
    } users[3] = {
      { "yeeted", "animo" },
      { "deleted", "animo" },
      { "dlsu", "animo" },
    };
    
    int validateUser(const char *username, const char *password) {
      for ( size_t i = 0 ; i < sizeof(users)/sizeof(*users) ; i++ ) {
        if ( strcmp(username,users[i].username) == 0 &&
             strcmp(password,users[i].password) == 0 ) {
          return 1;
        }
      }
      return 0;
    }
    
    void login(char *username, char *password) {
      printf("*************************************\n");
      printf("Enter your username: ");
      scanf("%s", username);
    
      printf("***********************************\n");
      printf("Enter your password: ");
      scanf("%s", password);
    }
    
    void signon_banner(void) {
        printf("***********************************\n");
        printf("Welcome back! You are now logged in! \n");
        printf("*************************************\n");
        printf("----------------------------------------------------------------------------\n");
        printf("                         Welcome to Sunny Breakfast Hub!\n");
        printf("                                Established 2020\n");
        printf("------------------------------------------------------------------------------\n");
    }
    
    //void (for menu) declarations
    void Menu(void);
    int Options(void);
    void TakeOrder(void);
    void OptionsGoingToReceipt(void);
    void Receipt(void);
    
    int main()
    {
      char username[20];
      char password[20];
      int option = 0;
    
      do {
        login(username, password);
        if( validateUser(username,password) )
          signon_banner();
          do {
            Menu();
            option = Options();
          } while ( option != 3 );
        } else {
          printf("***********************************");
          printf("\nUsername or Password is incorrect!");
          printf("\nPlease try again! ");
        }
      } while( option == 0 );
    }
    
    struct menuItem {
      int         code;
      const char *name;
      int         price;
    };
    
    #define MAX_MENU_ITEMS  10
    struct menu {
      const char  *name;
      struct menuItem items[MAX_MENU_ITEMS];
    };
    
    struct menu breakfasts = {
      "SUNNY BREAKFAST COMBOS",
      {
        { 101, "Chicken 'n Waffles", 200 },
        { 102, "Breakfast Burrito", 230 },
        { 103, "All American Platter", 400 },
        { 104, "Bacon Maniac w/ Eggs", 300 },
        { 105, "Classic Eggs Benedict", 250 },
        { 106, "Sausage Maniac w/ Eggs", 300 },
        { 107, "Fiesta Omelette", 250 },
        // the rest are automatically filled with zero
      }
    };
    
    struct menu sandwiches = {
      "ALL DAY SANDWICH",
      {
        { 201, "Honey Glazed Ham", 200 },
        { 202, "Tuna Mayo", 200 },
        { 203, "Chicken 'n Cheese", 180 },
        { 204, "Steak 'n Cheese", 250 },
        { 205, "Vegan Delight", 150 },
      }
    };
    
    struct menu pancakes = {
      "GOOD MORNING PANCAKES",
      {
        { 301, "Mixed Berries", 180 },
        { 302, "Blueberry", 180 },
        { 303, "Chocolate Chip", 150 },
        { 304, "Banana Walnut", 150 },
      }
    };
    
    struct menu drinks = {
      "SUNNY COFFEE AND REFRESHMENTS",
      {
        { 401, "Vanilla Milkshake", 120 },
        { 402, "Cappucino", 120 },
        { 403, "Mocha Frappucino", 100 },
        { 404, "Fresh Orange Juice", 80 },
      }
    };
    
    void menuHelper(const struct menu *left, const struct menu *right ) {
      printf("%-40s %-40s\n", left->name, right->name );
      for( int i = 0 ; i < MAX_MENU_ITEMS ; i++ ) {
        if ( left->items[i].code != 0 ) {
          printf("%3d %-26s P%3d    ", left->items[i].code,
                 left->items[i].name, left->items[i].price );
        } else {
          printf("%-40s", "" );
        }
        if ( right->items[i].code != 0 ) {
          printf("%3d %-26s P%3d", right->items[i].code,
                 right->items[i].name, right->items[i].price );
        }
        printf("\n");
      }
    }
    
    
    void Menu(void)
    {
      printf("=========================================================================\n");
      printf("                    SUNNY BREAKFAST HUB MENU\n");
      printf("=========================================================================\n");
      menuHelper(&breakfasts, &sandwiches);
      menuHelper(&pancakes, &drinks);
    }
    
    int Options(void)
    {
      int OptionCode;
      printf("=============================================================================\n");
      printf("                    SUNNY BREAKFAST HUB OPTIONS\n");
      printf("=============================================================================\n");
    
      printf("01    Back to Menu \n");
      printf("02    Take Order\n");
      printf("03    Exit Program\n");
      printf("Enter the Option Code here: \n");
      scanf("%i", &OptionCode);
    
      if( OptionCode == 2 ) {
        TakeOrder();
      }
    
      return OptionCode;
    }
    
    const struct menuItem *findItem(const struct menu *menu, int code ) {
      for( int i = 0 ; i < MAX_MENU_ITEMS ; i++ ) {
        if ( menu->items[i].code == code )
          return &menu->items[i];
      }
      return NULL;
    }
    
    //void function for TakeOrder
    void TakeOrder(void)
    {
      float price = 0;
      float TotalPrice = 0;
      float SubTotal = 0;
      int quantity;
      int trial;
      int MenuCode;
    
      do {
        printf("=============================================================================\n");
        printf("           Welcome to Sunny Breakfast Hub's Order Section!\n");
        printf("=============================================================================\n");
    
        printf("Please input the Menu Code of your order: ");
        scanf("%i", &MenuCode);
    
        // see if the item chosen is in any of the menus
        const struct menuItem *item = NULL;
        if ( !item ) item = findItem(&breakfasts, MenuCode);
        if ( !item ) item = findItem(&sandwiches, MenuCode);
        if ( !item ) item = findItem(&pancakes, MenuCode);
        if ( !item ) item = findItem(&drinks, MenuCode);
    
        if ( item ) {
          printf("You ordered: %s\n", item->name);
          printf("Quantity: ");
          scanf("%d", &quantity);
          price = item->price;
        }
    
        SubTotal = price * quantity;
        TotalPrice += SubTotal;
        printf("Subtotal: P%.2f", price);
        printf(" * %i", quantity);
        printf(" = P%.2f\n", SubTotal);
    
        printf("Do you want to purchase more?\n");
        printf(" -> Press (1) if you want to purchase more.\n");
        printf(" -> Press (0) if you want to proceed to checkout options.\n");
    
        printf("Please enter (1/0) here: ");
        scanf("%i", &trial);
      }
      while (trial == 1);
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    Apr 2020
    Posts
    8
    Quote Originally Posted by Salem View Post
    Some points to bear in mind.

    1. By convention (and because that's how it works), newlines go at the end of the string being output, not at the start.
    This is because when stdout is a terminal, the stream is typically line buffered, which means it gets flushed with every \n
    In short, printf("hello\n") has a much better chance of being seen than printf("\nhello").

    2. else if (OptionReceipt != 001 || OptionReceipt != 002 || OptionReceipt != 003)
    Beware that numeric constants with a leading zero indicate base 8 (octal) to the compiler, not base 10.
    You're fine up to 007 (Mr Bond), but try writing 008 and you're in for surprises.

    Oh, and before you copy/paste your way to another 1000 line program, here is something to study, and hopefully inspire you.
    Woahhhh, thanks so much for the lesson! I'm definitely learning more here compared to class. I'll bear these in mind, and I just can't stop looking at how short it could possibly be. Now I know what I should aim for. Thanks again.

    P.S.: I won't use this for submission, but this is definitely something I can check on when I need a reference in future projects.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 05-16-2019, 10:26 PM
  2. Replies: 5
    Last Post: 07-17-2016, 07:44 PM
  3. Printing the receipt
    By SiriusWhite in forum C Programming
    Replies: 1
    Last Post: 03-11-2014, 09:12 AM
  4. function call to print the smallest number?
    By mrcisco_89 in forum C Programming
    Replies: 5
    Last Post: 03-16-2013, 03:30 AM
  5. Receipt Machine in C
    By subwaybusker in forum C Programming
    Replies: 2
    Last Post: 10-21-2008, 12:18 PM

Tags for this Thread