stuck

B

Bill Cunningham

osmium said:
You could compute the desired result for all four good cases and pass
that value to a function that prints it.

Something like:

in oper():
double result;
...
if(c == 'a')
result = x+y;
// other three cases plus error detection case
...
print(result);

Do you mean printf here?
 
O

osmium

Bill Cunningham said:
Do you mean printf here?

No, this is a call to the function that *you* provide. As I understand you,
you wanted to prove you could kind of "hide" the call to printf - which is
later. This hides it by adding an (unnecessary) level of indirection..

Try it and see if it is what you want. If you didn't want to hide it,
reread the message you sent me about what you are trying to do. BTW, you
asked if it made sense and I didn't answer. No it doesn't make sense; but
students often do things that don't make sense to prove some point or other.
 
B

Bill Cunningham

osmium said:
No, this is a call to the function that *you* provide. As I
understand you, you wanted to prove you could kind of "hide" the call
to printf - which is later. This hides it by adding an (unnecessary)
level of indirection..

Yes.
Try it and see if it is what you want. If you didn't want to hide it,
reread the message you sent me about what you are trying to do. BTW,
you asked if it made sense and I didn't answer. No it doesn't make
sense; but students often do things that don't make sense to prove
some point or other.

Ok I think my question has been or is being answered and I will try
these tips and go on. If this works properly and I run into other problems
and retry and retry them and I just can't find the solution I will come to
the group.
Thanks.
 
N

Nick Keighley

why haven't you used a debugger?

Whether the code is wrong or right depends on what you want it to do,
which you haven't said -- yet.

This is a persistent problem, Bill.  [Can] you complete the comments I have
added?  I can *almost* figure out what oper() is supposed to do, then it
calls vop() for some reason unknown to me and I am baffled. I think you
wanted to print something but wanted to do it indirectly.  Might a macro be
be usefull here?  Is the object to save typing?  Or what?

// This function ....

that is, bill, he wants you to document what the function does (or is
supposed to do).

// This fucntion ...>> double vop(double oper)

Why overuse identifiers? There are plenty of unique identifiers to go
around, and uniqueness adds clarity.

I don't see that it necessaily does. Are all the parameter names
unique in the standard library?
 In other words:

double vop(double abc)
   {
   retrun printf("%.2f\n", abc):
   }
would be less confusing.

not significantly. Though having a function and a variable with the
same name is a bit odd. I think bill would be better using longer more
descriptive function names. Though that would involve him thinking
about the program and he's historically reluctent to do this (or he's
trolling).

<snip>
 
E

ec429

I don't see that it necessaily does. Are all the parameter names
unique in the standard library?
No, but more relevantly none (afaik) of the parameter names in the
standard library are also names of functions in the standard library;
similarly, none of the parameter names are also names of static
variables. (Of course, a static variable and a function can't have the
same name (assuming they're in the same compilation unit, or something))
In other words, identifiers generally shouldn't override each other; two
identifiers shouldn't have the same name if their scopes overlap
(typically, the scope of one being a subset of the scope of the other).
After all, it can get quite confusing when you wonder why some code
hasn't modified 'i', say, and don't realise that it's declared another
'i' in tighter scope.
Ultimately it's a coding style thing, and therefore subjective. But it
does make a lot of sense.
-Edward
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top