Thread: I need help in coding using void function

  1. #1
    Registered User
    Join Date
    Jan 2021
    Posts
    2

    Unhappy I need help in coding using void function

    I don't know how to code the receipt part of this program. Please help me. I'm a beginner.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    void MenuDisplay(void);
    void Order(void);
    void receipt(void);
    
    
    void MenuDisplay(void){
        printf("\t\t\t\t      Restaurant Name");
        printf("\n\n\t\t\t\t           MENU");
        printf("\n\t[1] Grilled Cheese\t80php\t [11] Squash Soup\t60php");
        printf("\n\t[2] Apple Cider Chicken\t120php\t [12] Vegetarian Chili\t100php");
        printf("\n\t[3] Steamed Green Beans\t95php\t [13] Ratatouille Salad\t110php");
        printf("\n\t[4] BBQ Pulled Pork\t130php\t [14] Bacon Frittata\t100php");
        printf("\n\t[5] Shrimp Pasta\t125php\t [15] Spicy Chicken\t130php");
        printf("\n\t[6] Bacon Swiss Burger\t110php\t [16] Rosemary Chicken\t140php");
        printf("\n\t[7] Chicken Parmesan\t120php\t [17] Smoked Salmon\t140php");
        printf("\n\t[8] Beef Lasagna\t90php\t [18] Tortilla Wrap\t80php");
        printf("\n\t[9] Mixed Green Salad\t85php\t [19] Braised Beef\t120php");
        printf("\n\t[10] Salmon Teriyaki\t150php\t [20] Beef Pot Roast\t160php\n\n");
        }
    
    
    void Order(void){
        int order, qty, total=0, more, charge=0;
        
        do{
        printf("\n\n\t\t\t   TAKE ORDER");
        printf("\n Enter [code number] Order: ");
        scanf("%d",&order);
        printf("\n Quantity: ");
        scanf("%d",&qty);
        
        if (order==1){
        charge = 80*qty;
        total +=charge;
        }
        
        if (order==2){
        charge = 120*qty;
        total +=charge;
        }
        
        if (order==3){
        charge = 95*qty;
        total +=charge;
        }
        
        if (order==4){
        charge = 130*qty;
        total +=charge;
        } 
        
        if (order==5){
        charge = 125*qty;
        total +=charge;
        }
        
        if (order==6){
        charge = 110*qty;
        total +=charge;
        }
        
        if (order==7){
        charge = 120*qty;
        total +=charge;
        }
        
        if (order==8){
        charge = 90*qty;
        total +=charge;
        }
        if (order==9){
        charge = 85*qty;
        total +=charge;
        }
        
        if (order==10){
        charge = 150*qty;
        total +=charge;
        }
        
        if (order==11){
        charge = 60*qty;
        total +=charge;
        }
        
        if (order==12){
        charge = 100*qty;
        total +=charge;
        }
        
        if (order==13){
        charge = 110*qty;
        total +=charge;
        }
        
        if (order==14){
        charge = 100*qty;
        total +=charge;
        }
        
        if (order==15){
        charge = 130*qty;
        total +=charge;
        }
        
        if (order==16){
        charge = 140*qty;
        total +=charge;
        }
        
        if (order==17){
        charge = 140*qty;
        total +=charge;
        }
        
        if (order==18){
        charge = 80*qty;
        total +=charge;
        }
        
        if (order==19){
        charge = 120*qty;
        total +=charge;
        }
        
        if (order==20) {
        charge = 160*qty;
        total +=charge;
        }
        
        charge=0;
        
        printf("\n Another Order? (1 for yes; 2 for no)");
        scanf("%d",&more);
    }
        while(more!=2);
        printf("\n%d",qty);
        printf("\n%d",charge);
        printf("\n%d",total);
    }
    
    
    void receipt(void){
        int totord,i, qty, charge, total;
        printf("Order\tQuantity\tPrice\n");
        printf("Order\t%d\t%d\t\t%d\n",qty, charge, total);
        
        for(i=0;i<totord;i++){
            
        }
        
    }
    
    
    main(){
        int select,choice;
        MenuDisplay();
        printf("OPTIONS");
        printf("\n 01 Back to Menu");
        printf("\n 02 Take Order");
        printf("\n 03 Exit");
        printf("\n\nSelect: ");
        scanf("%d",&select);
        if(select==1)
        {
            main();
        }
        else if(select==2)
        {
            Order();
        }
        else if(select==3){
            printf("Thank you for visiting");
        }
        printf("\n1 Receipt\n");
        printf("2 Options\n");
        printf("3 Exit\n");
        scanf("%d", &choice);
        switch(choice)
    {
        case 1:
            receipt();
            break;
        case 2:
            //print
        case 3:
            //exit
        default:
            printf("Wrong Input");
    }
        system("pause");
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,709
    You need a way to convey the order information from the order function to the receipt function.

    Code:
    void Order(int *orders) {
        printf("\n\n\t\t\t   TAKE ORDER");
        printf("\n Enter [code number] Order: ");
        scanf("%d",&order);
        printf("\n Quantity: ");
        scanf("%d",&qty);
        // arrays start at 0, but your menu starts at 1
        // so -1 when converting from user space to data space
        orders[order-1] += qty;  // add the quantity to their current total
    }
    
    void Receipt(int *orders) {
      static int prices[] = { 80, 120, 95 };  // todo
      for ( int i = 0 ; i < 3 ; i++ ) {
        total += orders[i] * prices[i];
      }
    }
    
    int main( ) {
      int orders[3] = { 0 };  // nothing ordered yet
      Order(orders);
      Receipt(orders);
    }
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. difference between void and static void function
    By mahaju in forum C++ Programming
    Replies: 7
    Last Post: 12-27-2011, 04:02 AM
  2. Hellp My Code!!!! Doesnt Work!!
    By icefire99 in forum C++ Programming
    Replies: 4
    Last Post: 04-24-2007, 05:36 AM
  3. Passing a variable in void to another void function
    By stevedawg85 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 06:17 PM
  4. HEllp!!! Please!!!
    By *Michelle* in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 12-21-2002, 07:53 AM
  5. Hellp!
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 05-30-2002, 10:56 AM

Tags for this Thread