473,394 Members | 1,889 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int total(int hi, int count);
  4.  
  5. int main (int)
  6. {
  7.     int n;        /*Input by the user*/
  8.     int m;        /*Input by the user*/
  9.     int lo;        /*Assigned the lower number*/
  10.     int hi;        /*Assigned the higher number*/
  11.     int count;
  12.  
  13.     /*Prompt the user to input 2 numbers*/
  14.  
  15.     printf("This program will add the range of numbers entered.");
  16.  
  17.     printf("\n\nEnter the low number and the high number.\n\n");
  18.  
  19.     /*Accept the user input*/
  20.  
  21.     scanf("%d%d", &n, &m);
  22.  
  23.     /*Determines the hi and lo*/
  24.  
  25.     lo = (n < m) ? n : m;        /*Assigns the lower number to lo*/
  26.     hi = (n > m) ? n : m;        /*Assigns the higher number to hi*/
  27.  
  28.     count = (hi - lo) + 1;        /*Counts the total number of numbers in range*/
  29.  
  30.     /*Call function*/
  31.  
  32.     total(hi, count);
  33.  
  34.     printf("\nThe sum of the range of numbers %d and %d is %d.\n\n", lo, hi, total(hi, count));
  35.  
  36.  
  37. }
  38.  
  39. #include <stdio.h>
  40. int total(int hi, int count)
  41.  
  42.     if (count == 1)
  43.         return (hi + 1);
  44.     else
  45.         return (hi + total(hi - (count - 1)));
  46.  
  47. }
  48.  
Nov 18 '07 #1
5 1182
scruggsy
147 100+
Expand|Select|Wrap|Line Numbers
  1. int total(int hi, int count);
  2.  
  3. ...
  4.  
  5. return (hi + total(hi - (count - 1)));
  6.  
  7.  
You're calling total(), which takes 2 arguments, with only 1 argument.
hi - (count - 1) is only one argument.
Nov 18 '07 #2
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?

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int total(int hi);
  4. int count(int hi, int lo);
  5.  
  6. int main (int)
  7. {
  8.     int n;        /*Input by the user*/
  9.     int m;        /*Input by the user*/
  10.     int lo;        /*Assigned the lower number*/
  11.     int hi;        /*Assigned the higher number*/
  12.  
  13.  
  14.     /*Prompt the user to input 2 numbers*/
  15.  
  16.     printf("This program will add the range of numbers entered.");
  17.  
  18.     printf("\n\nEnter the low number and the high number.\n\n");
  19.  
  20.     /*Accept the user input*/
  21.  
  22.     scanf("%d%d", &n, &m);
  23.  
  24.     /*Determines the hi and lo*/
  25.  
  26.     lo = (n < m) ? n : m;        /*Assigns the lower number to lo*/
  27.     hi = (n > m) ? n : m;        /*Assigns the higher number to hi*/
  28.  
  29.     count(hi, lo);
  30.  
  31.     /*Call function*/
  32.  
  33.     total(hi);
  34.  
  35.     printf("\nThe sum of the range of numbers %d and %d is %d.\n\n", lo, hi, total(hi));
  36.  
  37.  
  38. }
  39. #include <stdio.h>
  40.  
  41. int count(int hi, int lo);
  42. int total(int hi)
  43.  
  44.     if ((count(hi, lo)) = 1)
  45.         return (hi + 1);
  46.     else
  47.         return (hi + total(hi - ((count(hi, lo) - 1))));
  48.  
  49. }
  50. #include <stdio.h>
  51.  
  52. int count(int hi, int lo)
  53. {
  54.     int cnt = 0;
  55.  
  56.     cnt = (hi - lo) + 1;        /*Counts the total number of numbers in range*/
  57.  
  58.     return 1;
  59. }
  60.  
  61.  
Nov 18 '07 #3
Ganon11
3,652 Expert 2GB
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.
Nov 18 '07 #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.

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
Nov 19 '07 #5
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.
Nov 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
8
by: vpadial | last post by:
Hello, I want to build a library to help exporting c++ functions to a scripting languagge. The scripting language provides a function to register functions like: ANY f0() ANY f1(ANY) ANY...
6
by: marktm | last post by:
Hi- I am trying to use setInterval to call a method within an object and have not had any luck. I get "Object doesn't support this property or method" when I execute the following code. What I...
3
by: Thomas Barth | last post by:
Hi, I dont understand the third argument of this function. This function expect the address of a function, but what does "void *(*funktion)(void *)," mean? I am confused by so many "wildcards" :-)...
9
by: Marek Lewczuk | last post by:
Hello, I'm moving out from MySQL to PostgreSQL and there are some function which are not supported in PG so I'm trying to write my own functions. Currently I have big problem with function IF(),...
9
by: Jeffrey Baker | last post by:
Hi, I can't get my code to link. I get Example error LNK2019: unresolved external symbol "void __cdecl f(void *)" (?f@@YAXPAX@Z) referenced in function _main and Example fatal error LNK1120: 1...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
28
by: Bill | last post by:
Hello All, I am trying to pass a struct to a function. How would that best be accomplished? Thanks, Bill
3
by: linarin | last post by:
#include <iostream> using namespace std; typedef bool (*CallableFunction)(int argc,char* argv); void DefineMyFunction(const char* name,CallableFunction func){ //here do the define action. }...
4
by: istillshine | last post by:
I have a function foo, shown below. Is it a good idea to test each argument against my assumption? I think it is safer. However, I notice that people usually don't test the validity of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.