Thread: too few arguments

  1. #1
    Registered User
    Join Date
    Jun 2017
    Posts
    1

    too few arguments

    i try to insert paymentMethod() to the code but too few arguments error occured. could u please help me to fix the error? TQ

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    
    
    double price[7] = {15.80 , 10.50 , 19.00 , 14.00 , 12.00 , 22.00 , 16.00 };
    double mealTaxPrices[7];
    int adultNumber,childNumber;
    
    
    void printMeals();
    void orderMeals();
    double orderForAdult();
    double orderForChildren();
    void paymentMethod(int);
    int main()
    {
        char response = 'y';
    
    
         printMeals();
         while(response == 'y'|| response == 'Y')
        {
                printf("please enter number of adults  :");
                scanf("%d",&adultNumber);
    
                printf("please enter number of children:");
                scanf("%d",&childNumber);
    
    
                orderMeals();
    
                printf("\nwould you like to continue(y/n):");
                scanf("\n%c",&response);
    
                paymentMethod();
        }
    
     printf("\n      ******************** THANK YOU  *************************\n");
     printf("\**********************   PLEASE COME AGAIN  **************************\ \n");
       system("pause");
       return 0;
    }
    
    void printMeals()
    {
    
          printf("\20*******************  WELCOME TO MY RESTAURANT **************************\20\n");
          printf(" \t\t\t Below is the menue:\20\n");
          printf(" \t\t\t MEALS\t\t\tPRICE:\n");
          printf(" \t\t\t \22*******************************\22\n");
          printf(" \t\t\t 1- Fish and Chips\tRM15.80\n");
          printf(" \t\t\t 2- Spaghetti\t\tRM10.50\n");
          printf(" \t\t\t 3- T-Bone Steak\tRM19.00\n");
          printf(" \t\t\t 4- Chicken Chop\tRM14.00\n");
          printf(" \t\t\t 5- Chicken Maryland\tRM12.00\n");
          printf(" \t\t\t 6- Red Lobster\t\tRM22.00\n");
          printf(" \t\t\t 7- Seafood Platter\tRM16.00\n");
    
    
    
          printf("\n");
    }
    void orderMeals()
    {
    	double totalPriceForAdult, totalPriceForChildren;
    	double allPayment,discount;
             printf("                      \t\t**** ORDER MENU****\n");
    
    
            totalPriceForAdult =  orderForAdult();
            totalPriceForChildren = orderForChildren();
    		allPayment = totalPriceForAdult + totalPriceForChildren ;
    
         printf("\n \t\t     \22**************************************\22    \n");
         printf(" \t\t   ******************  TOTAL BILL   ************      \n");
         printf(" \t\t\tadult/child\tcount\t\ttotal price\n");
         printf(" \t\t\tadults\t\t%d\t\t%5.2f\n",adultNumber,totalPriceForAdult);
         printf(" \t\t\tchildren\t%d\t\t%5.2f\n",childNumber,totalPriceForChildren);
         printf(" \t\t\tTotal bill\t\t\t%5.2f\n",allPayment );
    
    
    
         if(allPayment < 10)
    		 discount=((allPayment * 0.5)/100);
         else if(allPayment>= 10 && allPayment<20)
              discount=((allPayment * 1)/100);
         else if(allPayment>= 20 && allPayment<30)
              discount=((allPayment * 1.5)/100);
         else if(allPayment>= 30 && allPayment<40)
              discount=((allPayment * 2.0)/100);
    	 else
    		  discount= ((allPayment * 5.0)/100);
    
              printf(" \t\t\tTotal bill after discount\t%5.2f\n",allPayment-discount);
    
    }
    double orderForAdult()
    {
         int menuOption,i,amount;
          char response = 'y';
          double totalPerPerson = 0.0,totalAllPerson = 0.0;
          double tax = 5.0;
          if(adultNumber <=0)
    		   printf("\n ");
    	  else
          printf("*\tadults:\n");
          for(i=0;i<adultNumber;i++)
         {
                   printf("adult %d please enter your orders\n",i+1);
                   while(response == 'y' || response == 'Y')
                   {
                                  printf("please enter your option:");
                                  scanf("%d",&menuOption);
    							  if(menuOption<1 || menuOption>7)
    							  {
    								  printf("sorry we don`t have this order \nagain! ");
    								  continue;
    							  }
                                  printf("please enter your amount of order:");
                                  scanf("%d",&amount);
    
    
                               totalPerPerson = totalPerPerson + (amount * price[menuOption - 1] );
    
                                  printf("\nWould you like to enter more orders(y/n):");
                                  scanf("\n%c",&response);
    
    
    
                   }
                   printf("\n");
                   totalAllPerson += totalAllPerson +  totalPerPerson;
                   totalPerPerson = 0.0;
                   response = 'y';
         }
    
         return totalAllPerson + ((totalAllPerson * tax) / 100);
    }
    double orderForChildren()
    {
           int menuOption,i,amount;
          char response = 'y';
          double totalPerChild = 0.0,totalAllChildren = 0.0;
          double tax = 5.0,oneOrder;
           if(childNumber <=0)
    		   printf("\n");
    	   else
           printf("*\tChildren:\n");
           for(i=0;i<childNumber;i++)
         {
                   printf("child %d please enter your orders\n",i+1);
                   while(response == 'y' || response == 'Y')
                   {
                                  printf("please enter your option:");
                                  scanf("%d",&menuOption);
    							  if(menuOption<1 || menuOption>7)
    							  {
    								  printf("sorry we don`t have this order \nagain! ");
                                      continue;
    							  }
                                  printf("please enter your amount of order:");
                                  scanf("%d",&amount);
    
                                  oneOrder = (price[menuOption - 1] * 60)/100 ;//this one order for a child with discount %60 of one order of adult
                                  totalPerChild = totalPerChild + (amount * oneOrder)  ;
    
    							  printf("Would you like to enter more orders(y/n):");
                                  scanf("\n%c",&response);
    
    
                   }
                   totalAllChildren += totalAllChildren +  totalPerChild;
                   response = 'y';
                   totalPerChild = 0.0;
    
                   printf("\n");
    
         }
    
         return totalAllChildren + ((totalAllChildren * tax) / 100);
    
    void paymentMethod()
    {
        int choice;
    
       start :
       printf("--------------------------------------------------------------------\n");
       printf("Select Payment Method:\n");
       printf("1) Cash\n");
       printf("2) Online Wallet\n");
       printf("3) Online Transaction\n");
       printf("5) Quit\n");
       printf("--------------------------------------------------------------------\n");
    
      do {
         scanf("%d", &choice);
         if (choice < 1 || choice > 5)
           printf("Invalid input.Try again \n");
       } while(choice < 1 || choice > 5);
    }
    }
    //}

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,323
    Quote Originally Posted by mars88
    i try to insert paymentMethod() to the code but too few arguments error occured. could u please help me to fix the error?
    Let's take a look at your forward declaration of paymentMethod:
    Code:
    void paymentMethod(int);
    So, paymentMethod is a function that has an int parameter and void return type. You neglected the parameter name, but that is legal in a forward declaration, though I would recommend including the parameter name anyway.

    Now, let's take a look at how you call it:
    Code:
    paymentMethod();
    You call paymentMethod as if it is a function that has no parameters. Clearly, there is a mismatch here. Finally, let's take a look at the start of your definition of paymentMethod:
    Code:
    void paymentMethod()
    {
    So, this matches how you call paymentMethod. Perhaps you should change the forward declaration of paymentMethod...

    Except that I note that a function that has no parameters and void return type can only have a net effect by side effects, or by changing global variables. From what I see, paymentMethod is intended to request the payment method from the user, which means that it must have some way to set that payment method such that the caller can access it. Now, you are indeed using global variables, but you should stop that immediately: your variables should only be local to a function, passed around as needed. Therefore, you probably also need to change paymentMethod to have a non-void return type, or possibly a pointer parameter.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with GCC arguments
    By NunoF in forum C Programming
    Replies: 8
    Last Post: 11-29-2016, 07:12 AM
  2. too many arguments
    By karfes in forum C Programming
    Replies: 3
    Last Post: 01-17-2009, 07:44 AM
  3. Arguments in MFC
    By guitarist809 in forum Windows Programming
    Replies: 2
    Last Post: 03-22-2008, 07:23 PM
  4. passing arguments using "Command Line Arguments"
    By Madshan in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2006, 03:46 PM
  5. Arguments
    By Narf in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 09-09-2005, 08:11 AM

Tags for this Thread