avg error

  • Thread starter Bill Cunningham
  • Start date
B

Bill Cunningham

I had this acg.c program working before now it won't even compile into
an obj file. I know because of the compiler's error reporting it's in the
return but it looks fine to me. Can I get a hint?

#include <stdio.h>
#ifdef STD
#include <stdlib.h>
#endif

double Avg(double *, int);
double Rsi(double, double);

The shared header.

#include "ta.h"

double Avg(double *num, int n)
{
double sum = 0.0;
int i;
for (i = 0; i < n; ++i)
sum += i[num];
return num / n;
}

The source file. And lastly the error.

avg.c: In function `Avg':
avg.c:9: invalid operands to binary /


Bill
 
B

Bill Cunningham

What do you think this error message means?

There is a problem in the return statement. The / is wrong. From there I
have no idea. Perhaps parenthesis are needed.

Bill
 
S

Seebs

There is a problem in the return statement. The / is wrong. From there I
have no idea. Perhaps parenthesis are needed.

I'm really fascinated by this.

Do you have this kind of problem with physical objects, or is it just
source code?

I just have this image of you posting to a car newsgroup:

My car door was working the other day, but I did some stuff and
now it doesn't. Specifically, it seems to fall off any time I try
to open it. Do I need new keys?

The operator "/" has two operands; in this case, "num" and "n". They
are invalid, says the compiler. Well, one starting point would be to think:
What are these operands, and should they work?

One of them is a pointer-to-double. One of them is an integer. Are you
trying to divide the pointer by the integer? If not, that might be your
problem. Maybe there is some value that you want to divide by some other
value. In which case, it seems as though maybe it would be the value
pointed to by the pointer, rather than the pointer itself.

I think you'll find that it gets a lot easier if you try to think through
things and assign meanings to symbols, then think about the relationships
between the things the symbols represent.

All the computer can do is follow instructions. If you get the instructions
wrong, the computer will do the wrong thing. If you told a computer to make
a peanut butter and jelly sandwich, and wrote "then put the lid of the peanut
butter on the bread", it would put the lid of the peanut butter on the bread,
and you'd post to Usenet saying "my sandwich came out all plasticy".

-s
 
J

jacob navia

Bill Cunningham a écrit :
There is a problem in the return statement. The / is wrong. From there I
have no idea.

Well, instead of trying to use somebody else's brain *maybe* (just maybe)
you could consider the possibility of turning on yours?

Brains CAN be useful for programming, and if yours is permanently disconnected
programming is difficult...

The problem with you is that there will always be somebody in this group that
will think for you. Then, you get used to it and do not think, do not make
any effort, etc. At each small problem you write here

HELP!

You have been bothering everyone since weeks with your stuff. Since this groups
has lost most traffic, you have a big forum of people that will try to spoil
you by answering every stupid question you happen to ask.

Perhaps parenthesis are needed.

Sure, just write:

return ((((((((((((((((((!)))))))))))))))))))
 
J

Joachim Schmitz

Bill said:
I had this acg.c program working before now it won't even compile
into an obj file. I know because of the compiler's error reporting
it's in the return but it looks fine to me. Can I get a hint?

#include <stdio.h>
#ifdef STD
#include <stdlib.h>
#endif

double Avg(double *, int);
double Rsi(double, double);

The shared header.

#include "ta.h"

double Avg(double *num, int n)
{
double sum = 0.0;
int i;
for (i = 0; i < n; ++i)
sum += i[num];
return num / n;
}

The source file. And lastly the error.

avg.c: In function `Avg':
avg.c:9: invalid operands to binary /

I guess you want

double Avg(double *num, int n)
{
double sum = 0.0;
int i;
for (i = 0; i < n; ++i)
sum += num;
return sum / n;
}

Bye, Jojo
 
L

Lew Pitcher

I had this acg.c program working before now it won't even compile into
an obj file. I know because of the compiler's error reporting it's in the
return but it looks fine to me. Can I get a hint?

#include <stdio.h>
#ifdef STD
#include <stdlib.h>
#endif

double Avg(double *, int);
double Rsi(double, double);

The shared header.

#include "ta.h"

double Avg(double *num, int n)
{
double sum = 0.0;
int i;
for (i = 0; i < n; ++i)
sum += i[num];
return num / n;
}

The source file. And lastly the error.

avg.c: In function `Avg':
avg.c:9: invalid operands to binary /

Bill, use your eyes. The compiler is telling you a LOT about why it can't
compile your program. Have you even looked at what it is telling you?

1) It tells you that the problem is in statement number 9. Did you look at
statement # 9? What does that statement do? What is it supposed to do?

2) It tells you that it has a problem with a division on that statement.

3) It tells you that one or more of the operands to that division in
statement 9 are invalid.

So, ***** look at statement number 9 *****

Here, I'll even point it out to you:
return num / n;

There is only one division in that statement, and that division has two
operands. So, the compiler is complaining that either num or n or both num
and n cannot participate in a division.

What is num? Can num be divided?
What is n? Can you divide something by n?


Believe me, your problem is obvious, if you properly answer those questions.
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
 
J

jacob navia

Seebs a écrit :
The operator "/" has two operands; in this case, "num" and "n". They
are invalid, says the compiler. Well, one starting point would be to think:

I think :)-) ) that Mr Cunningham has grown used to avoid ANY thinking
and relying on c.l.c to do the thinking for him.

You have AGAIN answered him, and spoiled him just a little bit MORE.

That guy needs that we stop thinking for him NOW!!!

Please stop answering those posts.

Thanks in advance.
 
J

jacob navia

I think that Mr Cunningham has grown used to avoid ANY thinking
and relying on c.l.c to do the thinking for him.

You have AGAIN answered him, and spoiled him just a little bit MORE.

That guy needs that we stop thinking for him NOW!!!

Please stop answering those posts.

Thanks in advance.
 
J

jacob navia

I think that Mr Cunningham has grown used to avoid ANY thinking
and relying on c.l.c to do the thinking for him.

You have AGAIN answered him, and spoiled him just a little bit MORE.

That guy needs that we stop thinking for him NOW!!!

Please stop answering those posts.

Thanks in advance.
 
J

Joachim Schmitz

jacob said:
I think that Mr Cunningham has grown used to avoid ANY thinking
and relying on c.l.c to do the thinking for him.

You have AGAIN answered him, and spoiled him just a little bit MORE.

That guy needs that we stop thinking for him NOW!!!

Please stop answering those posts.

Thanks in advance.

I have the feeling that you repeat yourself ;-)
 
J

jacob navia

Joachim Schmitz a écrit :
I have the feeling that you repeat yourself ;-)

Yeah I just can't stand that kind of brainless questions anymore!
Let's stop spoon feeding him ok?
 
K

Keith Thompson

jacob navia said:
Joachim Schmitz a écrit :

Yeah I just can't stand that kind of brainless questions anymore!
Let's stop spoon feeding him ok?

I do believe you've made your point. Repeating it won't help.
 
F

Flash Gordon

jacob said:
I think that Mr Cunningham has grown used to avoid ANY thinking
and relying on c.l.c to do the thinking for him.

You have AGAIN answered him, and spoiled him just a little bit MORE.

That guy needs that we stop thinking for him NOW!!!

Please stop answering those posts.

Thanks in advance.

I tend to agree with Jacob. People solving Bill's questions obviously is
not helping him learn C. It might be helping to keep him amused though.

Personally I tend to skip posts where I see Bill's name anywhere on the
first page. Not always, but most of the time.
 
C

chad

I think that Mr Cunningham has grown used to avoid ANY thinking
and relying on c.l.c to do the thinking for him.

You have AGAIN answered him, and spoiled him just a little bit MORE.

That guy needs that we stop thinking for him NOW!!!

Please stop answering those posts.

Thanks in advance.

I know a couple of Network Engineers in the San Francisco Bay Area
that can figure out any type of hardware related problem on a massive
LAN. But no matter how hard they try, they can't write simple computer
programs. It's like their brain isn't wired to think logically when it
comes to computer programming. Perhaps Mr Cunningham is the same way.
 
K

Keith Thompson

chad said:
I know a couple of Network Engineers in the San Francisco Bay Area
that can figure out any type of hardware related problem on a massive
LAN. But no matter how hard they try, they can't write simple computer
programs. It's like their brain isn't wired to think logically when it
comes to computer programming. Perhaps Mr Cunningham is the same way.

Bill has already explained the nature of his problem (apparently it's
a side effect of some medication).
 
B

Bill Cunningham

Seebs said:
I'm really fascinated by this.

Do you have this kind of problem with physical objects, or is it just
source code?

Unfortunately everything.

Bill
 
S

Seebs

Unfortunately everything.

That would be pretty frustrating. I'm not sure what to suggest other
than trying to be very methodical.

A novice was trying to fix a broken Lisp machine by turning the
power off and on.

Knight, seeing what the student was doing, spoke sternly: "You
cannot fix a machine by just power-cycling it with no
understanding of what is going wrong."

Knight turned the machine off and on.
The machine worked.

-s
 
U

user923005

Bill said:
   I had this acg.c program working before now it won't even compile
into an obj file. I know because of the compiler's error reporting
it's in the return but it looks fine to me. Can I get a hint?
#include <stdio.h>
#ifdef STD
#include <stdlib.h>
#endif
double Avg(double *, int);
double Rsi(double, double);
   The shared header.
#include "ta.h"
double Avg(double *num, int n)
{
   double sum = 0.0;
   int i;
   for (i = 0; i < n; ++i)
       sum += i[num];
   return num / n;
}
   The source file. And lastly the error.
avg.c: In function `Avg':
avg.c:9: invalid operands to binary /

I guess you want

double Avg(double *num, int n)
{
   double sum = 0.0;
   int i;
   for (i = 0; i < n; ++i)
       sum += num;
   return sum / n;

}

Bye, Jojo


Or even:
double Avg(const double *const num, const unsigned n)
{
double sum = 0.0;
unsigned i;
for (i = 0; i < n; ++i)
sum += num;
return sum / n;
}

#ifdef UNIT_TEST
#include <stdio.h>
int main(void)
{
static const double d[] = {
0.5, 1.0, 1.5
};
printf("average = %f (should be 1.0)\n", Avg(d, sizeof d / sizeof d
[0]));
return 0;
}
#endif
 
C

chad

Bill said:
   I had this acg.c program working before now it won't even compile
into an obj file. I know because of the compiler's error reporting
it's in the return but it looks fine to me. Can I get a hint?
#include <stdio.h>
#ifdef STD
#include <stdlib.h>
#endif
double Avg(double *, int);
double Rsi(double, double);
   The shared header.
#include "ta.h"
double Avg(double *num, int n)
{
   double sum = 0.0;
   int i;
   for (i = 0; i < n; ++i)
       sum += i[num];
   return num / n;
}
   The source file. And lastly the error.
avg.c: In function `Avg':
avg.c:9: invalid operands to binary /
I guess you want
double Avg(double *num, int n)
{
   double sum = 0.0;
   int i;
   for (i = 0; i < n; ++i)
       sum += num;
   return sum / n;

Bye, Jojo


Or even:
double          Avg(const double *const num, const unsigned n)
{
    double          sum = 0.0;
    unsigned        i;
    for (i = 0; i < n; ++i)
        sum += num;
    return sum / n;

}

#ifdef UNIT_TEST
#include <stdio.h>
int             main(void)
{
    static const double d[] = {
        0.5, 1.0, 1.5
    };
    printf("average = %f (should be 1.0)\n", Avg(d, sizeof d / sizeof d
[0]));
    return 0;}

#endif


What's the point of using #ifdef UNIT_TEST and #endif in your code?
Ie, what purpose does it serve.
 
B

Barry Schwarz

Bill Cunningham a écrit :

Well, instead of trying to use somebody else's brain *maybe* (just maybe)
you could consider the possibility of turning on yours?

Brains CAN be useful for programming, and if yours is permanently disconnected
programming is difficult...

Bill's brain is working perfectly. He has been successfully trolling
this newsgroup for years and never fails to reel in someone. Even
many who have sworn off responding still take the bait.

His most creative effort was a couple of months ago where he managed
to create a dozen threads on the same topic by changing one character
in the subject each time he responded. Each thread hooked another
sucker.

I wonder what the record is for the longest continuously active troll
on c.l.c. Or on any single newsgroup. Or maybe Usenet as a whole.

I hope people do what you asked in your other message because the
filter I use is useless when otherwise respectable posters respond to
him.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

avg 36
[C language] Issue in the Lotka-Volterra model. 0
seg fault 11
error in code 48
standard deviation 19
averages 2 24
Wants help in c program made with arrays and function 0
Access violation reading location 0

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top