Thread: please help , grand total not working and lunch not working

  1. #1
    Registered User
    Join Date
    Apr 2017
    Posts
    4

    please help , grand total not working and lunch not working

    Code:
    #include <stdio.h>		
    #include <ctype.h>
    #include <windows.h>
    
    
    void bfast();		
    void lunch();
    void dinner();
    void bill();
    void m_m(); 
    void exit();
    void fastfood();
    void riceitem();
    
    
    int num,i,lunch1;	
    float price;
    float total;
    float sum;
    float  grand;
    char choice;
    int again;
    float total13;
    float total11;
    float total12;
    float total0[3];
    
    
    int main()
    {
    	m_m();
    }
     void m_m()  // main menu screen
    {
    	char choice = ' ' ;
    
    
     
      printf("+======================================================+\n ");
      printf("|******************************************************|\n ");
      printf("|               Aslamalikum Sir/Mam.                   |\n ");
      printf("|         Hope you are having a Good day !             |    \n ");
      printf("|               Welcome to our Dhaba                   |\n ");
      printf("|******************************************************|\n ");
      printf("+======================================================+\n\n");
      printf("  && Please select the meal that you would like to purchase. && \n\n");
      printf("\t\t      [1] Nashta\n");
      printf("\t\t      [2] Lunch\n");
      printf("\t\t      [3] Dinner\n");
      printf("\t\t      [4] Exit\n\n");
      printf("Enter your choice here : ");
      scanf("%c", &choice);
      system("cls");
    
    
    	switch (toupper(choice))
        {
        case '1':
            bfast();
            break;
        case '2':
            lunch();
            break;
        case '3':
            dinner();
            break;
        case '4':
            exit();
        default:
            m_m();
            break;
        }
    
    
    
    
    }
    void bfast()
    {
      int choice= 0;
     int quantity= 0;
     int again= 0;
     
      float total1=0;
      float total2=0;
      float total3=0;
      float total4=0;
      float total5=0;
    
    
      
     
    
    
    
    
      fflush(stdin);
    
    
       printf("+======================================================+\n ");
      printf("|******************************************************|\n ");
      printf("|                Aslamalikum Sir/Mam.          ))      |\n ");
      printf("|         Hope you are having a Good day !             |    \n ");
      printf("|               Welcome to our Dhaba                   |\n ");
      printf("|             ***Nashty ka menu****                    |\n " );
      printf("|******************************************************|\n ");
      printf("+======================================================+\n\n");
    
    
      printf("  && Ap kia Nashta pasand Karengy. && \n\n");
      printf("\t\t   [1] Anda - PKR 30.0\n");
      printf("\t\t   [2] Paratha - PKR 15.0\n");
      printf("\t\t   [3] Chai- PKR 30.0\n");
      printf("\t\t   [4] chana salan- PKR 30.0\n");
      printf("\t\t   [5] mix sabzi - PKR 50.0\n");
     
    
    
      printf("Enter your choice here : ");
      scanf("%d", &choice);
      {   
      if ( choice == 1 ) 
    	  {
    	  printf(" quantity : ");
    	  scanf("%d", &quantity);
    	  total5 = 30.00 * quantity;
           printf("Apki abi tak ki wajibat rakam hai : PKR %.2f ,\n\n\n ", total5); 
    	  
    		  if ( choice == 2 )  
    		  {
    		  printf(" quantity : ");
    		  scanf("%d", &quantity);
    		  total1= 15 * quantity ;
    		  
    		  printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total1);
    	
    			}
    			}
    		  
    		  else 
    			  if ( choice == 3 )
    			  {
    			  printf(" Ap kitny lena chahengy : ");
    			  scanf("%d", &quantity);
    			  total2 = 30 * quantity ;
    			  
    			 printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total2);
    		  
    		     }
    		  else 
    			  if ( choice == 4 )
    			  {
    			  printf(" Ap kitny lena chahengy : ");
    			  scanf("%d", &quantity);
    			  total3 = 30 * quantity ;
    			  
    			 printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total3);
    		     
    			  }
    		  else 
    			  if ( choice == 5 )
    			  {
    			  printf(" Ap kitny lena chahengy : ");
    			  scanf("%d", &quantity);
    			  total4 = 50 * quantity ;
    			 
    			 printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total4);
    		    }	
    		
    		       printf("\nKia ap kuch or lena pasand karengy?\n[1] G , [2] Nai: "); 
    			   scanf("%d", &again);
    			   system("cls");
    		
    			  if (again == 1 )
    				{
    				bfast();
    				 }
    			  else 
    				  if (again == 2 )
    				{	
    					bill();
    	            exit();
    	        
    				}
    				else
    				    if (again != 1 , 2)
    					{
    					 printf("\n\n\t\t\tApka indarag galat hai !n\n\n\n");
    					 m_m();
    					} 		
          total11=total1+total2+total3+total4+total5;
          total0[0]=total11;
          printf("\n%.2f",total11);
    	  }
    
    
    }
      
      
        
    void lunch()
    {
      int choice=0; 
      int choice1=0; 
      int quantity=0;
      int again=0;
      
     
        
     
      printf("+======================================================+\n ");
      printf("|******************************************************|\n ");
      printf("|                Aslamalikum Sir/Mam.                  |\n ");
      printf("|         Hope you are having a Good day !             |    \n ");
      printf("|               Welcome to our Dhaba                   |\n ");
      printf("|               ***lunch ka menu****                   |\n " );
      printf("|******************************************************|\n ");
      printf("+======================================================+\n\n");
        printf(" '\n");
       printf("  && Ap kia lunch pasand Karengy. && \n\n");
       printf("\t\t   [1] RICE ITEMS\n");
       printf("\t\t   [2] FAST FOOD\n");
    
    
    
    
      printf(" &&& Apni pasand likhye &&& : ");
      scanf("%d", &choice);
       
      switch (choice)
        {
        case '1':
            riceitem();
            break;
        case '2':
            fastfood();
            break;
        default:
            m_m();
            break;
        }
    }
    
    
    void riceitem()
    	   {
      
      int choice1; 
      int quantity;
      int again;
      float total11=0;
      float total10=0;
      float total9=0;
      float total8=0;
      float total7=0;
      float total6=0;
    		printf("\t\t   [1] Chicken Biryani- PKR 120\n");
            printf("\t\t   [2] Beef Biryani- PKR 150 \n");
            printf("\t\t   [3] Chicken Pulao - PKR 150\n");
            printf("\t\t   [4] Beef Pulao - PKR 120\n");
            printf("\t\t   [5] Fried rice- PKR 150\n");
            printf("\t\t   [6] Fried Chicken rice- PKR 150\n");
    
    
             printf(" &&& Apni pasand likhye &&& : ");
             scanf("%d", &choice1);
    
    
    		  if ( choice1 == 1 )
    		{
    		
    	        printf("  Ap kitny lena chahengy : ");
    	        scanf("%d", &quantity);
    	        total11 = 120 * quantity ;
    	        
    		}
    
    
    		  if ( choice1 == 2 )
    		  {
    		  printf("Ap kitny lena chahengy : ");
    		  scanf("%d", &quantity);
    		  total10= 150 * quantity ;
    		   
    	}
    		  
    		  
    		     if ( choice1 == 3 )
    			  {
    			  printf(" Ap kitny lena chahengy : ");
    			  scanf("%d", &quantity);
    			  total9= 150 * quantity ; 
    		 }
    		  else 
    			  if ( choice1 == 4 )
    			  {
    			  printf(" Ap kitny lena chahengy : ");
    			  scanf("%d", &quantity);
    			  total8 = 120 * quantity ;
    			    
    			 printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total8);
    		}
    			  
    		     else 
    			    if ( choice1 == 5 )
    			  {
    			  printf(" Ap kitny lena chahengy : ");
    			  scanf("%d", &quantity);
    			  total7 = 150 * quantity ;
    		
    			 printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total7);
    		    
    		}
    	  else 
    			  if ( choice1 == 6 )
    			  {
    			  printf(" Ap kitny lena chahengy : ");
    			  scanf("%d", &quantity);
    			  
    			    
    			 printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total6);
    	}
    			
    }
    	void  fastfood()
    	   {
    	 
      int choice1=0; 
      int quantity=0;
      int again=0;
      float total12=0;
      float total13=0;
      float total15=0;
      float total14=0;
      float total17=0;
      float total16=0;  
       	
    	   	printf("\t\t   [1] Chicken Broast- PKR 150\n");
            printf("\t\t   [2] Spicy Broat- PKR 170 \n");
            printf("\t\t   [3] Chicken Burger - PKR 160\n");
            printf("\t\t   [4] Beef Burger - PKR 150\n");
            printf("\t\t   [5] zinger- PKR 180\n");
            printf("\t\t   [6] Mighty zinger PKR 250\n");
            
             printf(" &&& Apni pasand likhye &&& : ");
             scanf("%d", &choice1);
     
     
    	  	if(choice1 == 1)
    	  	   {
    		
    	        printf("  Ap kitny lena chahengy : ");
    	        scanf("%d", &quantity);
    	        total17 = 150 * quantity ;
    	        printf("Apki abi tak ki wajibat rakam hai : PKR %.2f ,\n\n\n ", total17); 
    	       
               }  
    	else 
    		  if ( choice1 == 2)
    		  {
    		  printf("Ap kitny lena chahengy : ");
    		  scanf("%d", &quantity);
    		  total14 = 170 * quantity ;
    		  printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total14);
    		 
    		  }
    		  else 
    			  if ( choice1 == 3)
    			  {
    			  printf(" Ap kitny lena chahengy : ");
    			  scanf("%d", &quantity);
    			  total15 = 160 * quantity ;
    			 printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total15);
    		     
    		     }
    		  else 
    			  if ( choice1 == 4 )
    			  {
    			  printf(" Ap kitny lena chahengy : ");
    			  scanf("%d", &quantity);
    			  total13= 150 * quantity ;
    			 printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total13);
    		       
    			  }
    		  else 
    			  if ( choice1 == 5 )
    			  {
    			  printf(" Ap kitny lena chahengy : ");
    			  scanf("%d", &quantity);
    			  total12 = 150 * quantity ;
    			 printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total12);				
    	         }
        	  else 
    			  if ( choice1 == 6 )
    			  {
    			  printf(" Ap kitny lena chahengy : ");
    			  scanf("%d", &quantity);
    			  total16 = 250 * quantity ;
    			 printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total16);	   	
                  }
               printf("\nKia ap kuch or lena pasand karengy?\n[1] G , [2] Nai: "); 
    			   scanf("%d", &again);
    			   system("cls");
    			   
    			  if (again == 1 )
    				{
    				lunch();
    				 }
    			  else 
    				  if (again == 2 )
    				{	
    					bill();
    	            exit();
    				}
    				else
    				    if (again != 1 , 2)
    					{
    					 printf("\n\n\t\t\tApka indarag galat hai !n\n\n\n");
    					 m_m();
    					} 	
    		}
    
    
    
    
    void dinner() 
    {
      int choice;  
      int quantity;
      int again;
      float total14=0;
      float total12=0;
      float total13=0;
      
    
    
      printf("+======================================================+\n ");
      printf("|******************************************************|\n ");
      printf("|                Aslamalikum Sir/Mam.                  |\n ");
      printf("|         Hope you are having a Good day !             |\n ");
      printf("|               Welcome to our Dhaba                   |\n ");
      printf("|               ***Dinner ka menu****                  |\n ");
      printf("|******************************************************|\n ");
      printf("+======================================================+\n\n");
      printf("  && Please select the food that you would like to purchase. && \n\n");
      printf("\t\t   [1] Chicken Chop - 650\n");
      printf("\t\t   [2] Spagetti - 550\n");
      printf("\t\t   [3] Chicken Burger - 400\n");
    
    
      printf("&&& Apni pasand likhye &&& : ");
      scanf("%d", &choice);
      {
      if (choice == 1) 
    	  {
    	  printf(" quantity : ");
    	  scanf("%d", &quantity);
    	  total14 = 650 * quantity ;
    
    
    	  printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total14);
    	    
          }
    	else 
    		  if ( choice == 2)
    		  {
    		  printf("quantity : ");
    		  scanf("%d", &quantity);
    		  total12 = 550 * quantity ;
    
    
    		  printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total12);
    		
    	
    		  }
    		  else 
    			  if ( choice == 3 )
    			  {
    			  printf("quantity : ");
    			  scanf("%d", &quantity);
    			  total13 = 400 * quantity ; 
    			  
    			   
    			 printf(" Apki abi tak ki wajibat rakam hai : PKR : %.2f\n\n\n ", total13);
    		}
    				printf("\nKia ap kuch or lena pasand karengy?\n[1] G , [2] Nai: "); 
    				scanf("%d", &again);
    				system("cls");
    				if (again == 1 )
    					dinner();
    				else 
    					if (again == 2 )
    				{
    				bill();
    	            exit();
    	        }
    				else
    					if (again != 1 , 2)
    					{	
    					 printf("\n\n\t\tApka indarag galat hai !\n\n\n\n");
    					 m_m();
    					}
    			
    				 }
    	total13=total14+total12+total13;
    	total0[2]=total13;
    }
    	
    		 
    	
    
    
    
    
    
    
    void exit()
    {
      printf("\n+====================================================+\n ");
      printf("\n|****************************************************|\n ");
      printf("\n|               Aslamalikum Sir/Mam.                 |\n ");
      printf("\n|         Hope you are having a Good day !           |\n ");
      printf("\n|****************************************************|\n ");
       printf("\n|****************************************************|\n ");
      printf("\n|                  Thank You Very Much               |\n ");
      printf("\n|            +============================+          |\n\n");
      printf("\n|            && Please come again. && \n\n           |\n");
      printf("\n+====================================================+\n ");
      printf("\n|****************************************************|\n ");
       }
    void bill()
    {
    total0[3]=total0[0]+total0[1]+total0[2];
     printf("\n|                 grand total : %.2f                 |\n",total0[3]);
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Sure, work your way through these warnings.
    It helps if you have a decent compiler with lots of warnings enabled.

    Code:
    $ gcc -Wall -Wextra -Wshadow foo.c
    foo.c: In function ‘m_m’:
    foo.c:35:7: warning: declaration of ‘choice’ shadows a global declaration [-Wshadow]
      char choice = ' ' ;
           ^
    foo.c:21:6: note: shadowed declaration is here
     char choice;
          ^
    foo.c:53:3: warning: implicit declaration of function ‘system’ [-Wimplicit-function-declaration]
       system("cls");
       ^
    foo.c: In function ‘bfast’:
    foo.c:80:7: warning: declaration of ‘choice’ shadows a global declaration [-Wshadow]
       int choice= 0;
           ^
    foo.c:21:6: note: shadowed declaration is here
     char choice;
          ^
    foo.c:82:6: warning: declaration of ‘again’ shadows a global declaration [-Wshadow]
      int again= 0;
          ^
    foo.c:22:5: note: shadowed declaration is here
     int again;
         ^
    foo.c:186:24: warning: left-hand operand of comma expression has no effect [-Wunused-value]
             if (again != 1 , 2)
                            ^
    foo.c: In function ‘lunch’:
    foo.c:203:7: warning: declaration of ‘choice’ shadows a global declaration [-Wshadow]
       int choice=0; 
           ^
    foo.c:21:6: note: shadowed declaration is here
     char choice;
          ^
    foo.c:206:7: warning: declaration of ‘again’ shadows a global declaration [-Wshadow]
       int again=0;
           ^
    foo.c:22:5: note: shadowed declaration is here
     int again;
         ^
    foo.c:206:7: warning: unused variable ‘again’ [-Wunused-variable]
       int again=0;
           ^
    foo.c:205:7: warning: unused variable ‘quantity’ [-Wunused-variable]
       int quantity=0;
           ^
    foo.c:204:7: warning: unused variable ‘choice1’ [-Wunused-variable]
       int choice1=0; 
           ^
    foo.c: In function ‘riceitem’:
    foo.c:250:7: warning: declaration of ‘again’ shadows a global declaration [-Wshadow]
       int again;
           ^
    foo.c:22:5: note: shadowed declaration is here
     int again;
         ^
    foo.c:251:9: warning: declaration of ‘total11’ shadows a global declaration [-Wshadow]
       float total11=0;
             ^
    foo.c:24:7: note: shadowed declaration is here
     float total11;
           ^
    foo.c:253:9: warning: variable ‘total9’ set but not used [-Wunused-but-set-variable]
       float total9=0;
             ^
    foo.c:252:9: warning: variable ‘total10’ set but not used [-Wunused-but-set-variable]
       float total10=0;
             ^
    foo.c:251:9: warning: variable ‘total11’ set but not used [-Wunused-but-set-variable]
       float total11=0;
             ^
    foo.c:250:7: warning: unused variable ‘again’ [-Wunused-variable]
       int again;
           ^
    foo.c: In function ‘fastfood’:
    foo.c:330:7: warning: declaration of ‘again’ shadows a global declaration [-Wshadow]
       int again=0;
           ^
    foo.c:22:5: note: shadowed declaration is here
     int again;
         ^
    foo.c:331:9: warning: declaration of ‘total12’ shadows a global declaration [-Wshadow]
       float total12=0;
             ^
    foo.c:25:7: note: shadowed declaration is here
     float total12;
           ^
    foo.c:332:9: warning: declaration of ‘total13’ shadows a global declaration [-Wshadow]
       float total13=0;
             ^
    foo.c:23:7: note: shadowed declaration is here
     float total13;
           ^
    foo.c:416:24: warning: left-hand operand of comma expression has no effect [-Wunused-value]
             if (again != 1 , 2)
                            ^
    foo.c: In function ‘dinner’:
    foo.c:428:7: warning: declaration of ‘choice’ shadows a global declaration [-Wshadow]
       int choice;  
           ^
    foo.c:21:6: note: shadowed declaration is here
     char choice;
          ^
    foo.c:430:7: warning: declaration of ‘again’ shadows a global declaration [-Wshadow]
       int again;
           ^
    foo.c:22:5: note: shadowed declaration is here
     int again;
         ^
    foo.c:432:9: warning: declaration of ‘total12’ shadows a global declaration [-Wshadow]
       float total12=0;
             ^
    foo.c:25:7: note: shadowed declaration is here
     float total12;
           ^
    foo.c:433:9: warning: declaration of ‘total13’ shadows a global declaration [-Wshadow]
       float total13=0;
             ^
    foo.c:23:7: note: shadowed declaration is here
     float total13;
           ^
    foo.c:498:21: warning: left-hand operand of comma expression has no effect [-Wunused-value]
          if (again != 1 , 2)
                         ^
    foo.c: In function ‘exit’:
    foo.c:517:6: warning: number of arguments doesn’t match built-in prototype
     void exit()
          ^
    foo.c:530:4: warning: ‘noreturn’ function does return
        }
        ^
    The problems are
    1. You have an over reliance on global variables.
    2. None of your functions take parameters or return results.
    3. Your exit function must be called something else to avoid problems with the real exit function.
    4. Your variable naming is vague, non-descriptive - and therefore unhelpful.
    5. Your bill() function has an out of bound memory access.

    All those 'variable shadows variable' issues mean you're updating one variable, while you might be thinking you're updating another.
    FYI, the variable with the nearest scope is the one that always wins.

    Before you next try and write a 500+ line program only to find out it doesn't work, read this.
    A development process
    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.

  3. #3
    Registered User
    Join Date
    Apr 2017
    Posts
    4
    Thank you so much , can you help fixing them , i m new in c , and dont know all these

  4. #4
    Registered User
    Join Date
    Apr 2017
    Posts
    4
    i u sing dev c++ and its not showing such errors , out is coming but worng

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by tubbaedhi View Post
    i u sing dev c++ and its not showing such errors , out is coming but worng
    Step 1: Learn the name and version of your compiler.
    Step 2: Learn where to find the build log (The output of the compiler during compilation and linking)
    Step 3: Learn how to turn up warnings on your compiler using the IDE interface.

    Tim S.
    Last edited by stahta01; 04-28-2017 at 08:28 AM. Reason: Fixed Typos
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    If by dev c++, you mean this one -> Bloodshed Software - Dev-C++, then it's obsolete (web page last updated 05 Feb 2003).

    If you want something up to date, which works the same then use Dev-C++ download | SourceForge.net

    > Thank you so much , can you help fixing them , i m new in c , and dont know all these
    I told you what was wrong.
    You can start by fixing the names of all your variables so there are no shadows.

    If by "help" you mean, will you rewrite 500 lines of code for me, then the answer will always be no.
    We're guides for your journey, not mules to carry you.
    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. pogram not shoing grand total =0 , tried alot
    By tubbaedhi in forum C Programming
    Replies: 1
    Last Post: 04-27-2017, 06:55 AM
  2. Replies: 4
    Last Post: 02-25-2016, 08:49 AM
  3. Replies: 26
    Last Post: 07-03-2010, 03:57 PM
  4. Replies: 9
    Last Post: 03-30-2009, 04:09 AM
  5. grand total
    By gunshipolitico in forum C++ Programming
    Replies: 1
    Last Post: 11-13-2005, 08:57 PM

Tags for this Thread