too many arguments to function ' ' at this point in file - c

I'm having the problem...
error: too many arguments to function 'EPJ calc'
error: at this point in file
This code works perfectly if I reduce the number of variables to 6 instead of 11 in the whole process. Can anybody explain why, and a way around this? In the assigment I have to be able to repeat the process 10 times.
void loop()
{
calc(&person[cc].reacTime[0], &person[cc].reacTime[1], &person[cc].reacTime[2],
&person[cc].reacTime[3], &person[cc].reacTime[4], &person[cc].reacTime[5],
&person[cc].reacTime[5], &person[cc].reacTime[6], &person[cc].reacTime[7],
&person[cc].reacTime[8], &person[cc].reacTime[9], &person[cc].midvaerdi);
Serial.print("Average time for person ");
Serial.print(cc);
Serial.print(" ");
Serial.println(person[cc].midvaerdi);
}
struct EPJ calc(float *num1,float *num2,float *num3,float *num4,
float *num5,float *num6,float *num7,float *num8,
float *num9,float *num10,
float *midval)
{
float temp;
temp = (*num1 + *num2 + *num3 + *num4 + *num5 +
*num6 + *num7 + *num8 + *num9 + *num10);
Serial.print("Temp number : ");
Serial.println(temp);
*midval = (temp)/nRepeat;
Serial.print("midval number : ");
Serial.println(*midval);
}

It looks you are calling calc with 12 arguments, but it is defined accepting only 11.

It looks like a simple typo error while calling calc(). You've supplied &person[cc].reacTime[5] twice as parameter.

Related

Why my c program only produce zero answer while using for loop?

I tried to use for loop calculate the number of books keyed in and sum up their total price, but at the end i only get zero price in C program. What is my problem ? How to solve it?
#include<stdio.h>
int main(void)
{
int booknum;
float bookfee,bookgst,nogst,totfee,newfee,newfee_nogst;
bookgst=0.0;
nogst=0.0;
int cnt;
char code;
printf("Key in total books purchased >> ");
scanf("%d",&booknum);
for(cnt=1;cnt<=booknum;cnt++)
{
printf("\n\n");
printf("Key in price of the book >> ");
scanf("%f",&bookfee);
printf("Key in type( S=standard gst,Z=zero gst) \n>> ");
scanf("%c",&code);
getchar();
if(code=='S')
{
newfee=bookfee+0.6;
}
else if(code=='Z')
{
newfee_nogst=bookfee;
}
bookgst=bookgst+newfee;
nogst=nogst+newfee_nogst;
printf("\n");
}
totfee=bookgst+nogst;
printf("Book purchased with GST : RM %.2f\n",bookgst);
printf("Book purchased without GST : RM %.2f\n",nogst);
printf("Total payment : RM %.2f\n",totfee);
return 0;
}
There are a few problems with this code, but you're almost there!
First code reading needs to eat the previous \n (see this), otherwise the code is neither Z not S (it's a newline), and that's why the fees are never added.
(Search also for "fgets vs scanf" to see how to use the safer fgets).
scanf(" %c",&code);
then these lines
bookgst=bookgst+newfee;
nogst=nogst+newfee_nogst;
add the newfee / newfee_nogst ; these variables are set to 0 before the loop, but at the next occurence, they're still set to the value of the previous occurrence, thus either set them to 0 at the beginning of the loop, or, add the value directly in the if (see below). And since we're here, print an error if the code is wrong (and maybe subtract one to cnt to do one more loop with a correct code, in this case).
Also, the GST calculation is probably wrong, 6% of x is 0.06 * x, and if you want GST added to the value that's x * 1.06
if(code=='S')
{
bookgst = bookgst + bookfee*1.06; // or bookgst += bookfee*1.06
}
else if(code=='Z')
{
nogst = nogst + bookfee; // or nogst += bookfee
}
else {
printf("Code not understood\n");
}

cs50 pset1 water.c I am getting error while compiling

following code is throwing compiling error. I am new to programming and so dont know what else to do. I did as taught in the class but cant get it right. cam anyone please help me solve it?
#include<stdio.h>
#include<cs50.h>
int main(void)
{
int y;
do
{
printf("Minutes: ");
int Minutes = get_int();
}
while(Minutes< 0);
y= Minutes * 12;
printf("Bottles: %i\n", y);
}
it is throwing following error:
water.c:10:8: error: unused variable 'Minutes' [-Werror,-Wunused-variable]
int Minutes = get_int();
^
water.c:12:7: error: use of undeclared identifier 'Minutes'
while(Minutes< 0);
^
water.c:14:4: error: use of undeclared identifier 'Minutes'
y= Minutes * 12;
^
3 errors generated.
make: *** [water] Error 1
You defined Minutes in the scope of the do block. That means it can only be used within that same scope - ie. between the {} enclosing the block.
You are however using the variable outside of that scope (twice in fact).
Instead, define Minutes before the do loop :
int Minutes = 0;
do {
printf("Minutes: ");
Minutes = get_int();
}
while(Minutes< 0);
This puts it in the scope of the main function body, so it can be used anywhere in the main function (after its definition).
int Minutes is declared local to the loop body, meaning that the loop condition while(Minutes< 0) has no idea what "Minutes" is.
Simply move the declaration out of the loop, above it.
This is the answer
#include <cs50.h>
#include <stdio.h>
int main(void)
{
printf("minutes: ");
int minutes = get_int();
printf("bottles: ");
int bottles = get_int();
printf("%i\n divided %i\n is %i\n", minutes, bottles, minutes / bottles);
}

Please anybody check my code to see what's wrong with it

#include <stdio.h>
int getAvg(int a, int b, int c);
int main()
{
int a,b,c;
int i;
int avg[5];
char name[5][10] ;
int korean[5], english[5], maths[5] ;
char message[2][10] = {"Pass","No Pass"};
for ( i = 0; i < 5; i++ )
{
printf("Enter your marks <name,korean,english,maths \n");
scanf("%s%d%d%d",name[i],&korean[i],&english[i],&maths[i]);
}
for (i = 0; i < 5; i++)
{
printf("name:%s, korean:%d, english:%d, maths:%d, average:%d",name[i],korean[i],english[i],maths[i],avg[i]);
avg[i] = getAvg(a,b,c);
if (avg[i]>60)
{
printf("==%s",message[0]);
}
else
{
printf("==%s",message[1]);
}
}
int getAvg(int a, int b, int c)
{
int avg;
avg = (a+b+c)/3;
return avg;
}
}
I want to print like this
Enter your marks <name,korean,english,maths>
kim 10 50 60
Enter your marks <name,korean,english,maths>
hanna 50 60 70
Enter your marks <name,korean,english,maths>
lee 80 70 60
Enter your marks <name,korean,english,maths>
lori 70 80 90
Enter your marks <name,korean,english,maths>
kang 60 70 80
name:kim,korean:10,english:50,maths:60,average:40 == no pass
name:hanna,korean:50,english:60,maths:70,average:60 == no pass
name:lee,korean:80,english:70,maths:60,average:70 == pass
name:lori,korean:70,english:80,maths:90,average:80 == pass
name:kang,korean:60,english:70,maths:80,average:70 == pass
I'm really sorry if it turns out to be my mistakes or the question is too elementary.. it's due in 5 hours and i couldn't figure out what's wrong.. it keeps telling me that the getAve function is undefined reference and i see nothing wrong with it.. please anybody kindly help me? :(
Your getAvg is inside main. Move it out (or, equivalently, move one outer brace from end of your code to just above getAvg definition start). There is also something wrong with the calculation of averages, but that's a logical error, not a syntactic one. (Specifically, you're calculating the average of a, b and c - check where you define the value of those variables, and you're printing stuff before you calculate it).
You get "undefined reference to getAvg function" because you did not close main before defining the getAvg function. Just move the last } before the function definition and that error should be gone !
Then,You call the function like this
avg[i] = getAvg(a,b,c);
But a,b and c are uninitialized ! So you need
a=korean[i];
b=english[i];
c=maths[i];
Before it. You also print avg[i] before you calculate it. So, move the printf after the function call to get the desired results.
After fixing your brace positioning, also there is a problem here:
printf("name:%s, korean:%d, english:%d, maths:%d, average:%d",name[i],korean[i],english[i],maths[i],avg[i]);
avg[i] = getAvg(a,b,c);
You have to calculate the average before you display it. Also, a, b, c are uninitialized variables. You probably meant:
avg[i] = getAvg( korean[i], english[i], maths[i] );
printf("name:%s, korean:%d, english:%d, maths:%d, average:%d",
name[i], korean[i], english[i], maths[i], avg[i]);
first you put getAvg(...) outside of main()
now call getAvg(...) before printing avg[i];
avg[i] = getAvg(korean[i],english[i],maths[i]);
printf("name:%s, korean:%d, english:%d, maths:%d, average:%d",name[i],korean[i],english[i],maths[i],avg[i]);

Function definition not allowed / [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
My professor gave us this code in class to show how a program works and said "go home and try it and you'll see it works".... well after 30 minutes I cannot get it to run. can someone please help me and point me in the right direction. Thank you!
-I get function definition on the end "double g(double x)"
-On the first else where x_left = x_mid control reaches end of non-void function
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define FALSE 0
#define TRUE 1
#define NO_ROOT -99999.0
//function prototypes
double bisect(double, double, double, double f(double farg));
// evaluation of function
double g(double);
double h(double);
int main(void) {
double x_left, x_right, epsilon, root; //declare variables
// get endpoint and error tolerance
printf("\nEnter interval endpoints > ");
scanf("%lf%lf", &x_left, &x_right);
printf("\nEnter tolerance > ");
scanf("%lf", &epsilon);
//use bisect function to look for roots of functions
printf("\n\n For function g(x)");
root = bisect(x_left, x_right, epsilon, g);
if (root != NO_ROOT)
printf("\n g(%.7f) = %e\n", root, g(root));
printf("\n\n For function h(x)");
root = bisect(x_left, x_right, epsilon, h);
if (root != NO_ROOT)
printf("\n h(%.7f) = %e\n", root, h(root));
system("pause");
return (0);
}
// bisection method program coding
double bisect(double x_left, double x_right, double epsilon, double f(double farg)){
double x_mid, f_left, f_right, f_mid;
int root_found;
// computes function at initial end points
f_left = f(x_left);
f_right = f(x_right);
// if no change in sign
if (f_left * f_right > 0) {
printf("\nmay not be no root in [%.7f, %.7f]\n\n", x_left, x_right);
return NO_ROOT;
}
// searches as long as interval size is large enough
root_found = FALSE;
while (fabs(x_right - x_left) > epsilon && !root_found) {
// compute the mid point
x_mid = (x_left + x_right) / 2.0;
f_mid = f(x_mid);
if (f_mid == 0.0) {
root_found = TRUE;}
else if (f_left * f_mid < 0.0) {
x_right = x_mid;
} else {
x_left = x_mid;
}
// trace loop execution
if (root_found)
printf("\nRoot found at x = %.7f , midpoint of [%.7f, %.7f] ", x_mid, x_leftx_right);
else
printf("\nNew interval is [%.7f, %.7f] \n\n", x_left, x_right);
//if there is a root
return ((x_left + x_right)/2.0);
}
// functions for which roots are sought
double g(double x){
return (5 * pow(x, 3.0) - 2 * pow(x, 2.0) +3);
}
double h(double x){
return (pow(x, 4.0) - 3 * pow(x,2.0) - 8);
};
}
I get an error on this line:
printf("\nRoot found at x = %.7f , midpoint of [%.7f, %.7f] ", x_mid, x_leftx_right
saying that x_leftx_right is undeclared.
If I change this to x_left, x_right then it compiles OK except for "undefined reference to g" and "undefined reference to h".
The reason for the undefined reference to g is that you never provided a function definition for the function g that was prototyped by double g(double);. You did provide a nested function g within bisect. Nested functions are a non-standard extension, and bisect::g is a different function to g. Similarly for h.
To fix this, move the definitions of g and h to be after the end of the bisect function; instead of inside that function.
The reason for your "control reaches end of non-void function" warning is probably because there is no return statement after the while loop.
Your line return ((x_left + x_right)/2.0); line is within the loop begun by while (fabs(x_right - x_left) > epsilon && !root_found) {. If this loop finishes by the loop condition no longer being true, then the execution hits the end of the function without returning anything.
NB. If you indent your code properly so that you line up { then you are less likely to have this sort of problem. Your editor should have a key that you can use to find matching curly-braces. Also, operating your compiler in strict standard mode would have given an error about the use of nested function.
`

Not a pointer, Cannot dereference

Iam writing a code in C where structure is being passed by reference and is used in another function
Following is the called function declaration:
float Compute(float input, struct constraints* limits_record, struct constraints* state_record);
Where limits_record and state_records both are structure declared as below:
struct constraints
{
float lower_limit;
float upper_limit;
};
The above function is being called from another function(not from main) as follows:
autotrim_out=Compute(inp, &limit, &state);
Following code details about the Compute function:
float Compute(float input, struct constraints* limits_record, struct constraints* state_record)
{
float tmp_lim;
float tmp_intgr;
tmp_intgr = coefficient * (input + state_record->lower_limit) + state_record->upper_limit;
if (tmp_intgr < limits_record->lower_limit)
tmp_lim = limits_record->lower_limit ;
else if(tmp_intgr > limits_record->upper_limit)
tmp_lim = limits_record->upper_limit;
else
tmp_lim = tmp_intgr;
state_record->upper_limit = tmp_lim;
state_record->lower_limit = input ;
return(tmp_lim) ;
}
On compiling the above code is giving error "Not a pointer, cannot deference" on the line
tmp_intgr = coefficient * (input + state_record->lower_limit) + state_record->upper_limit;
Can someone please help me regarding this...
Thanks in advance
Look for something in you code like:
#define coefficient
and change it to:
#define coefficient .42

Resources