Function argument error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mosullivan
    New Member
    • Nov 2007
    • 12

    Function argument error?

    I don't know where the problem with my program is. I keep getting an error that says the function doesn't take 1 argument. I have two arguments listed for the function everytime I mention it. The error is said to be in line 46. Any help would be great.

    Code:
    #include <stdio.h>
    
    int total(int hi, int count);
    
    int main (int)
    {
    	int n;		/*Input by the user*/
    	int m;		/*Input by the user*/
    	int lo;		/*Assigned the lower number*/
    	int hi;		/*Assigned the higher number*/
    	int count;
    
    	/*Prompt the user to input 2 numbers*/
    
    	printf("This program will add the range of numbers entered.");
    
    	printf("\n\nEnter the low number and the high number.\n\n");
    
    	/*Accept the user input*/
    
    	scanf("%d%d", &n, &m);
    
    	/*Determines the hi and lo*/
    
    	lo = (n < m) ? n : m;		/*Assigns the lower number to lo*/
    	hi = (n > m) ? n : m;		/*Assigns the higher number to hi*/
    
    	count = (hi - lo) + 1;		/*Counts the total number of numbers in range*/
    	
    	/*Call function*/
    
    	total(hi, count);
    	
    	printf("\nThe sum of the range of numbers %d and %d is %d.\n\n", lo, hi, total(hi, count));
    
    	
    }
    
    #include <stdio.h>
    int total(int hi, int count)
    
    { 
    	if (count == 1)
    		return (hi + 1);
    	else
    		return (hi + total(hi - (count - 1)));
    		
    }
  • scruggsy
    New Member
    • Mar 2007
    • 147

    #2
    Originally posted by mosullivan
    Code:
    int total(int hi, int count);
    
    ...
    
    return (hi + total(hi - (count - 1)));
    You're calling total(), which takes 2 arguments, with only 1 argument.
    hi - (count - 1) is only one argument.

    Comment

    • mosullivan
      New Member
      • Nov 2007
      • 12

      #3
      Ok, I understand that. I've changed it so that count is a function and now I'm getting an error that says 'lo' is an undeclared identifier. Both hi and lo are identified in the main - is there something I'm missing?

      Code:
      #include <stdio.h>
      
      int total(int hi);
      int count(int hi, int lo);
      
      int main (int)
      {
      	int n;		/*Input by the user*/
      	int m;		/*Input by the user*/
      	int lo;		/*Assigned the lower number*/
      	int hi;		/*Assigned the higher number*/
      	
      
      	/*Prompt the user to input 2 numbers*/
      
      	printf("This program will add the range of numbers entered.");
      
      	printf("\n\nEnter the low number and the high number.\n\n");
      
      	/*Accept the user input*/
      
      	scanf("%d%d", &n, &m);
      
      	/*Determines the hi and lo*/
      
      	lo = (n < m) ? n : m;		/*Assigns the lower number to lo*/
      	hi = (n > m) ? n : m;		/*Assigns the higher number to hi*/
      
      	count(hi, lo);
      	
      	/*Call function*/
      
      	total(hi);
      	
      	printf("\nThe sum of the range of numbers %d and %d is %d.\n\n", lo, hi, total(hi));
      
      	
      }
      #include <stdio.h>
      
      int count(int hi, int lo);
      int total(int hi)
      
      { 
      	if ((count(hi, lo)) = 1)
      		return (hi + 1);
      	else
      		return (hi + total(hi - ((count(hi, lo) - 1))));
      		
      }
      #include <stdio.h>
      
      int count(int hi, int lo)
      {
      	int cnt = 0;
      
      	cnt = (hi - lo) + 1;		/*Counts the total number of numbers in range*/
      
      	return 1;
      }

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        What is that mess at the end? You are #include <stdio.h> three times, and you declare count twice before defining. There's no need for the extra definitions and #includes after the top of the program. Anyway, your problem is in total - you use count(hi, lo), but you never got lo from main, only a variable named hi as an argument.

        Comment

        • mosullivan
          New Member
          • Nov 2007
          • 12

          #5
          Originally posted by Ganon11
          What is that mess at the end? You are #include <stdio.h> three times, and you declare count twice before defining. There's no need for the extra definitions and #includes after the top of the program. Anyway, your problem is in total - you use count(hi, lo), but you never got lo from main, only a variable named hi as an argument.

          The mess are the two functions. I guess I should have titled them so I didn't cause any confusion. I'll look at total again. Thanks

          Comment

          • mosullivan
            New Member
            • Nov 2007
            • 12

            #6
            Originally posted by mosullivan
            The mess are the two functions. I guess I should have titled them so I didn't cause any confusion. I'll look at total again. Thanks
            I started over and have completed the assignment. Thanks for all your help.

            Comment

            Working...