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. -
#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)));
-
-
}
-
5 1182 -
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.
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? -
#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;
-
}
-
-
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.
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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" :-)...
|
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(),...
|
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...
|
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)
{
|
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
|
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.
}...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
|
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...
|
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...
|
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...
| |