Why is return from my function is nan?

U

utab

Dear all, I posted this yesterday since it was a sunday, many people
missed it I guess and I could not find the answer.

I tried sth easy(actually this was an exercise) but I tried to use the
standard lib. heavily for this problem(as far as I can). There was one
point I could not figure out. The problem is :

../a.out 1.3+3.2+.1+40/3*8/7-4*5-32

The program will parse the argument and find the result of the above
expression. I have two versions(the 2nd is working , not perfect ;-}),
but the first have a return problem I guess because if I use that
version I get "nan" as the result at line 37. What is my problem?

Sorry that there are some comments and cout statement in around the
code. But I guess it could be easier to figure out.

You can find the two versions of the code here:

http://groups.google.be/group/comp.lang.c++/browse_thread/thread/
7ac73062c56a73a2/074abc747f2964e5?hl=en#074abc747f2964e5

One gentle poster commented on that UNIX may be expanding '*' to
wildcards, I tried that it is not the problem. I quoted and supplied
the expression. Probably I am missing sth quite easy.
 
O

Ondra Holub

utab napsal:
Dear all, I posted this yesterday since it was a sunday, many people
missed it I guess and I could not find the answer.

I tried sth easy(actually this was an exercise) but I tried to use the
standard lib. heavily for this problem(as far as I can). There was one
point I could not figure out. The problem is :

./a.out 1.3+3.2+.1+40/3*8/7-4*5-32

The program will parse the argument and find the result of the above
expression. I have two versions(the 2nd is working , not perfect ;-}),
but the first have a return problem I guess because if I use that
version I get "nan" as the result at line 37. What is my problem?

Sorry that there are some comments and cout statement in around the
code. But I guess it could be easier to figure out.

You can find the two versions of the code here:

http://groups.google.be/group/comp.lang.c++/browse_thread/thread/
7ac73062c56a73a2/074abc747f2964e5?hl=en#074abc747f2964e5

One gentle poster commented on that UNIX may be expanding '*' to
wildcards, I tried that it is not the problem. I quoted and supplied
the expression. Probably I am missing sth quite easy.

You should place here your code (minimized as possible, but still
showing the problem). Few people will try to resolve not-working link
(at least for me the presented link is broken).
 
S

Sami Vaaraniemi

utab said:
Dear all, I posted this yesterday since it was a sunday, many people
missed it I guess and I could not find the answer.

I tried sth easy(actually this was an exercise) but I tried to use the
standard lib. heavily for this problem(as far as I can). There was one
point I could not figure out. The problem is :

./a.out 1.3+3.2+.1+40/3*8/7-4*5-32

The program will parse the argument and find the result of the above
expression. I have two versions(the 2nd is working , not perfect ;-}),
but the first have a return problem I guess because if I use that
version I get "nan" as the result at line 37. What is my problem?

Sorry that there are some comments and cout statement in around the
code. But I guess it could be easier to figure out.

You can find the two versions of the code here:

http://groups.google.be/group/comp.lang.c++/browse_thread/thread/
7ac73062c56a73a2/074abc747f2964e5?hl=en#074abc747f2964e5

One gentle poster commented on that UNIX may be expanding '*' to
wildcards, I tried that it is not the problem. I quoted and supplied
the expression. Probably I am missing sth quite easy.

Compiling the code gives this warning:

": warning: 'performer' : not all control paths return a value"

That should give you a hint as to what is wrong with the code.

Regards,
Sami
 
U

utab

": warning: 'performer' : not all control paths return a value"
That should give you a hint as to what is wrong with the code.


But if I add a "cout << vec_d[0] << endl;" before return under "else":

I can see the output is right and there. if it is there why is it not
returned correctly?

My best
 
O

Ondra Holub

utab napsal:
": warning: 'performer' : not all control paths return a value"
That should give you a hint as to what is wrong with the code.


But if I add a "cout << vec_d[0] << endl;" before return under "else":

I can see the output is right and there. if it is there why is it not
returned correctly?

My best

Look on my answer in your first thread. You have there something like:

if (condition)
{
// here is missing return
}
else
{
return result;
}

So although result is valid, it is not returned and return value is
undefined.
 
U

utab

if (condition)
{
// here is missing return}else
{
return result;

}So although result is valid, it is not returned and return value is
undefined.

Since the function is recursive, on the next run it does not return a
value, now I got that. It was simple.

Best regards
 

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,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top