Thread: Printing the receipt

  1. #1
    Registered User SiriusWhite's Avatar
    Join Date
    Mar 2014
    Location
    Jamaica
    Posts
    9

    Printing the receipt

    Code:
    # include <conio.h>
    # include <stdio.h>
    # include <stdlib.h>
    # include <string.h>
    
    
    #define PASSWORD 161996
    #define TEXTSIZE  80
    #define TAX 0.01
    #define NUM_BREAKFAST_ITEMS  3
    #define NUM_LUNCH_ITEMS 3
    #define NUM_DINNER_ITEMS 3  
    #define NUM_DESSERT_ITEMS 6
    #define NUM_BEVERAGE_ITEMS 6
     
    struct MenuData {
      char  name[TEXTSIZE];
      char  desc[2][TEXTSIZE];
      char  prepare[2][TEXTSIZE];
      float price;
    };
    
    
    typedef struct MenuData MenuData;
    
    
    
    
    /*Initialization of array elements MenuData*/
    
    
    const MenuData breakfast[NUM_BREAKFAST_ITEMS] = {
    
    
      {"Egg Breakfast", "Two eggs with a side of bacon and two slices of toast.", "", "2 Eggs, 2 Toats, 2 Bacons", "", 250.00},
    
    
      {"Pancake Breakfast", "Three Buttermilk pancakes, butter and syrup.", "", "Three Pancakes, Butter, Syrup", "", 200.00},
    
    
      {"Meat Variety", "Three eggs, bacon and", "smoked sausages,porridge, three fried dumplings and jam.", "1 Bowl Poridge,", "3 Fried Dumplings, Jam", 350.00}
    
    
    };
    
    
    const MenuData lunch[NUM_LUNCH_ITEMS]= {
    	
    	{"Cheese Burger", " Thick-sliced bacon and two slices of tastee", "cheese served with seared buns and fries.", "Cheese Burger, Fries", "", 450.00,},
    	
    	{"Hotdog N' Fries", "Smoked sausages, Hotdog Rolls with seasoned Fries.", "", "Smoked Sausage Hotdog, Seasoned Fries", "", 345.60,},
    	
    	{"Chicken Feet Soup", "Chicken feet soup, with boiled dumplings", "yellow yam, sweet potato and 5 slices garlic bread.", "Chicken soup- Boiled Dumplings, Yellow", "Yam, Sweet Potato, 5 Garlic Bread", 445.60}
    	
    };
    
    
    const MenuData dinner [NUM_DINNER_ITEMS]= {
    	{"Sunday Dinner", "Fried Chicken served with rice and peas and macaroni salad", "", "Fried Chicken, Rice and Peas, Macaroni Salad", "", 600.00,},
    	
    	{"Pastas N' Such", "Macaroni casserole topped with an assortment of cheese","served with mashed potatoes and baked chicken", "Macaroni Casserole, Four Cheese Topping", "Mashed Potatoes, Baked Chicken", 450.00,},
    	
    	{"Real Jamaican Dinner", "Ackee and saltfish served with boiled dumplings", "yam and irish potatoes", "Ackee and Saltfish, Boiled dumplings, Yam", "", 395.00,}
    };
    
    
    const MenuData dessert [NUM_DESSERT_ITEMS]= {
    	{"Rock Cakes","", "", "Rock Cakes", "", 70.00,},
    	
    	{"Gizzarda", "", "", "Gizzarda", "", 95.50,},
    	
    	{"Fruit Cake", "", "", "Fruit Cake", "", 200.00,},
    	
    	{"Apple Pie Slice", "", "", "Apple Pie Slice", "", 300.00,},
    	
    	{"Cheese Cake Slice", "","", "Cheese Cake Slice", "", 300.00,},
    	
    	{"Fudge Cupcake", "","", "Fudge Cupcake", "", 100.00,}
    	
    };
    
    
    const MenuData beverage [NUM_BEVERAGE_ITEMS]= {
    	{"Hot Chocolate", "", "", "Hot Chocolate", "", 60.00,},
    	
    	{"Coffee", "", "", "Coffee", "", 50.00,},
    	
    	{"Soft Drink", "", "", "Soft Drink", "", 90.00,},
    	
    	{"Beer", "", "", "Beer", "", 150.00,},
    	
    	{"Wine", "", "", "Wine", "", 250.00,},
    	
    	{"Water", "", "", "Water", "", 75.00,}
    	
    };
    
    
    /*End of initialization*/
    
    
    
    
    struct customerInfo {
    	int customer_num;
    	char cashier_name[20], client_name[20];
    }; typedef struct customerInfo info;
     
    /*Fuction Declarations*/ 
    void interface (); 
    int orderFunction (const MenuData menu[], int);
    int EnterQuantity ();
    float Subtotal (const MenuData menu[], int, int, int);
    float Caltotal (float, float);
    float Tax (float);
    void printReceipt (const MenuData menu[], int, float, float, int);
    
    
    
    
    enum options {
    	opt1= 1,
    	opt2= 2,
    	opt3= 3,
    	opt4= 4,
    	opt5= 5,
    	opt6= 6
    };
    
    
    enum MenuTime {
        Breakfast=1, 
    	Lunch=2,
    	Dinner=3,
    	Dessert=4,
    	Beverage=5,
    	Receipt=6,
    	Exit=7
    };
    
    
    /* display any menu data */
    
    
    void displayMenu(const MenuData menu[], int numofitems)
    {
      int i;
      printf("\n");
      for(i=0; i<numofitems; i++) {
        printf("%d. %s \n",       i+1, menu[i].name);
        printf("Description: %s \n",   menu[i].desc[0]);
        if( strlen(menu[i].desc[1]) > 0 )
        printf("%s \n",              menu[i].desc[1]);
        printf("Price: $%.2f \n",      menu[i].price);
        printf("\n");
      }
    }
    
    
    int main (int total, int subtot)
    {
    	interface ();
    	info in1;
    	int ch;
    	MenuData menu;
    	int password;
    	int count;
    	enum MenuTime Mchoice;
    	enum options choices;
    	
    	count=3;
    
    
    	for (int i=0; i=count; i++)
    	{
    		printf ("\n\t\tEnter Your Cashier Name: ");
    	    scanf ("%s", in1.cashier_name);
    		printf ("\n");
    		printf ("\n\t\tEnter the Password: ");
    		scanf ("%d", &password);
    	
    	    system ("cls");
    	    
           	if (password== PASSWORD)
    		{
    		 	interface ();
    		 	
    		 	FILE *cfPtr;
                if ((cfPtr= fopen ("Food.txt", "a"))==NULL)
             	{
                   printf ("File could not be opened\n");
             	}
             	
    	 	    printf ("\n");
    		    printf ("Enter the Client's name\n:");
    		    scanf ("%s", in1.client_name);
    
    
                printf ("Enter the Client's Table number\n:");
    	        scanf ("%d", &in1.customer_num);
    	        
    
    
    	        fprintf (cfPtr, "\n");
    	        fprintf (cfPtr, "Customer Name: %s\n", in1.client_name);
    	        fprintf (cfPtr, "Table Number: %d\n", in1.customer_num);
    	        
    	        
    		    while (1)
    		 	{ 
    	            
    	            system ("cls");
                	interface ();
                	printf ("\n");
                    printf ("---------------#Welcome to Main Menu#----------------\n");
                    printf ("\n");
                    printf ("\tPress 1 for the Breakfast Menu\n");
                    printf ("\tPress 2 for the Lunch Menu\n");
                    printf ("\tPress 3 for the Dinner Menu\n");
                    printf ("\tPress 4 for the Desert Menu\n");
                    printf ("\tPress 5 for the Beverage Menu\n");
                    printf ("\tPress 6 to Print Receipt\n");
                    printf ("\tPress 7 to Exit\n");
                    scanf ("%d", &Mchoice);
     	  
     	            while ((ch = getchar()) != '\n' && ch != EOF);
     	            
                	switch (Mchoice) 
    				{	
    					case Breakfast:		
    					    system ("cls");
    					    printf ("\t.........Breakfast Menu............\n");
    						displayMenu(breakfast, NUM_BREAKFAST_ITEMS);
    						orderFunction (breakfast, NUM_BREAKFAST_ITEMS);
    						getch ();
            	    		break;
     	  		
                 		case Lunch:
                 			system ("cls");
                 			printf ("\t.........Lunch Menu..........\n");
                		    displayMenu(lunch, NUM_LUNCH_ITEMS);
                		    orderFunction (lunch, NUM_LUNCH_ITEMS);
                		    getch ();
                		    break;
    			
                		case Dinner:
                			system ("cls");
                			printf ("\t.........Dinner Menu.........\n");
                		    displayMenu (dinner, NUM_DINNER_ITEMS);
                		    orderFunction (dinner, NUM_DINNER_ITEMS);
                		    getch ();
                			break;
    				
                		case Dessert:
                		    system ("cls");
                		    printf ("\t.........Desseert Menu.........\n");
                 			displayMenu (dessert, NUM_DESSERT_ITEMS);
                 			orderFunction (dessert, NUM_DESSERT_ITEMS);
                 			getch ();
                			break;
    				
                		case Beverage:
               				system ("cls");
               				printf (".........Beverage Menu........\n");
               			    displayMenu (beverage, NUM_BEVERAGE_ITEMS);
               			    orderFunction (beverage, NUM_BEVERAGE_ITEMS);
               			    getch ();
               				break;
               	
               			case Receipt:
                          	printReceipt (breakfast, NUM_BREAKFAST_ITEMS, subtot, total, choices);
                          	printReceipt (lunch, NUM_BREAKFAST_ITEMS, subtot, total, choices);
                          	printReceipt (dinner, NUM_BREAKFAST_ITEMS, subtot, total, choices);
                          	printReceipt (dessert, NUM_BREAKFAST_ITEMS, subtot, total, choices);
                          	printReceipt (beverage, NUM_BREAKFAST_ITEMS, subtot, total, choices);
               				break;
               				
                		case Exit:	
    					    exit (1);
    						break;
    	
    				
               			default:
             	            printf ("This Option Doesn't Exist!\n");
               	    	   break;
    						  	
    				    
        	        } // End Switch
        	        	
    	    	 }//End while
                 
            }//End if
             
             else
    		
    		printf ("Invalid Password!\n");
    		count=count-1;
    		printf ("You have %d tries left!\n", count);
    		
        }//End For
        	
    	printf ("This program will close.\n");
    	printf ("\n");
    
    
        getch ();
    } // end main
    
    
    
    
    
    
    void interface ()
    {	
    	 printf ("\t Welcome to Master's Restaurant and Bar!\n");
         printf ("\n");
    	
    	  printf ("                                          o8             \n");        
          printf ("                                          888            \n");             
          printf ("        ooo. .oo. .ooo.      ooo d8b      888oooo.       \n"); 
          printf ("        888P'Y88bP'Y88b      888''8p      d88' `88b      \n"); 
          printf ("        888   888   888      888          888   888      \n");   
          printf ("        888   888   888      888          888   888      \n");
          printf ("       o888o o888o o888o    d888b         `Y8bod8P'      \n");
     
    }//End of Interface
    
    
    int EnterQuantity ()
    {
    	int qty;
    	printf ("Enter Quantity: ");
    	scanf ("%d", &qty);
    	return qty;
    }
    
    
    int orderFunction (const MenuData menu[], int numofitems)
    {
    	enum options choices;
    	int i, ch;
    	int qty;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF);
    	printf ("Enter Choice: ");
    	scanf ("%d", &choices);
    	
    	if (choices==0|| choices > numofitems)
    	{
           printf ("Invalid Option.\nPress any key to return to Main Menu.");
    	}
    	
    	EnterQuantity ();
    	
    	FILE *cfPtr;
        if ((cfPtr= fopen ("Food.txt", "a"))==NULL)
       	{
           printf ("File could not be opened\n");
       	}
     	  	                 	
         if  (choices== opt1 || choices== opt2 || choices== opt3|| choices== opt4 || choices==opt5 || choices== opt6)
         {                 	  
            fprintf (cfPtr, "Prepare: %s\n", menu[choices-1].prepare[0]);
            if (strlen(menu[choices-1].prepare[1]) > 0 )
            fprintf (cfPtr, "%s\n", menu[choices-1].prepare[1]);
            fprintf (cfPtr, "________________________________________________");
            fprintf (cfPtr, "________________________________________________\n");
        }
       
        
        fclose (cfPtr);
        
        return choices;
        
    }//End of Function
    
    
    float Subtotal (const MenuData menu[], int qty, int choices, int numofitems)
    {
    	
    	int i;
    	float subtot;
    	
    	for(i=0; i<numofitems; i++)
    	{	  
        		subtot=menu[i].price*qty;
        }
    	return subtot; 
    }
    
    
    float Tax (float subtot)
    {
    	float tax;
    
    
    	tax= subtot* TAX;
    	
    	return tax;
    
    
    }
    
    
    float Caltotal (float tax, float subtot)
    {
    	float total;
    	
    	total= tax+ subtot;
    	
    	return total;
    }
    
    
    void printReceipt (const MenuData menu[], int numofitems, float subtot, float total, int choices)
    {
    	int i;
    	float cash_tender;
    	float change;
    	
    	system ("cls");
    	
        printf ("                      8         \n");
    	printf ("                      88        \n");
    	printf ("                      88ooo.    \n");
        printf (" oo. .o. .oo   oo d8b d8'  `8b  \n");
        printf (" 88P'Y88'Y88   88'    88    88  \n");
        printf ("o88o     o88o d88b    `YbodP'  \n");
    	printf ( "\n");
    	printf ("        ** RECIEPT**           \n");
    	printf ("\n");
    	printf ("\n");
    	printf ("5 Kingston Road, Lot 5\n");
    	printf ("\n");
    	printf ("\n");
    	printf ("Item Bought             Price\n");
        
       for(i=0; i<numofitems; i++)
        {
             printf ("%s         \t$ %.2f\n", menu[i].name,  menu[i].price);  
        }
        
        printf ("Subtotal              $ %.2f\n", subtot);
        printf ("Toatl Sale            $ %.2f\n", total);
        printf ("\n");
        
        
        printf ("To calculate change, ");
        system ("pause");
    	printf ("Enter the cash tendered by customer: ");
    	scanf ("%f", &cash_tender);
    	
    	change= total-cash_tender;
    	printf ("The change id %.2f", change);
    		
    }
    I want to print the receipt but it won't print properly. The price isn't calculating properly and the items that I chose won't come out when I print it.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Why did you start a new topic for this existing problem?

    Jim

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printing Receipt using C programming
    By danial92 in forum C Programming
    Replies: 8
    Last Post: 08-30-2011, 01:31 PM
  2. Receipt Machine in C
    By subwaybusker in forum C Programming
    Replies: 2
    Last Post: 10-21-2008, 12:18 PM
  3. Printing non-printing characters in ^ and M- notation
    By sbeard22 in forum C Programming
    Replies: 6
    Last Post: 10-03-2008, 11:12 PM
  4. Help with printing something
    By kdc6794 in forum C Programming
    Replies: 4
    Last Post: 02-26-2002, 12:58 PM
  5. Printing
    By fred_scotland in forum C Programming
    Replies: 3
    Last Post: 02-21-2002, 04:32 PM

Tags for this Thread