PDA

View Full Version : Yes or No decision problem




hawkeye10
Feb 3, 2012, 03:45 AM
Hi guys! I'm kinda new to programming and I really need help.

http://i188.photobucket.com/albums/z162/ervintrn25/ScreenShot2012-02-03at53748PM.png

so i keep getting this "Exc_Bad_Access" every time I enter "y"


Would you like to take your BMI using Meters(height) &
Kilograms(weight)? (y/n): y
Current language: auto; currently minimal
(gdb)


I would really appreciate the help guys :D



KnightWRX
Feb 3, 2012, 04:19 AM
You're passing a char to scanf. What does scanf expect to receive ? Is a char appropriate ?

Here, I'll give you a strong hint, the appropriate lines in the man page :

Each successive pointer argument must correspond properly with each suc-
cessive conversion specifier (but see the * conversion below). All con-
versions are introduced by the % (percent sign) character.

mydogisbox
Feb 3, 2012, 06:29 AM
I'm going to steal from Sesame Street a bit here.

One of these things is not like the others:

scanf(" %c", ans1);
scanf("%lf", &Meters);
scanf("%lf", &Kilograms);

gnasher729
Feb 3, 2012, 08:29 AM
I would really appreciate the help guys :D

For the future: Go to your project settings, and check what compiler warnings you can turn on. The compiler is able to tell you about the exact kind of mistake that you made.

KnightWRX
Feb 3, 2012, 09:02 AM
For the future: Go to your project settings, and check what compiler warnings you can turn on. The compiler is able to tell you about the exact kind of mistake that you made.

That's why I always compile with -Wall on the command line. Never ignore a warning!

gnasher729
Feb 3, 2012, 12:45 PM
That's why I always compile with -Wall on the command line. Never ignore a warning!

Any new code of mine uses "warnings = errors", including analyser warnings. So I _cannot_ ignore any warnings. (And there is quite a high percentage of warnings that are actually serious bugs. It's easy to miss a '&' as the OP did. The compiler can find it if you let it).

chrono1081
Feb 3, 2012, 12:52 PM
To the OP's defense I've seen several code sites that are missing what he is missing. He may have been looking off of one of those sites.

KnightWRX
Feb 3, 2012, 12:53 PM
Any new code of mine uses "warnings = errors", including analyser warnings. So I _cannot_ ignore any warnings. (And there is quite a high percentage of warnings that are actually serious bugs. It's easy to miss a '&' as the OP did. The compiler can find it if you let it).

Considering I've been dragging my ass on a warning for like 3 months on my current project (Something about Class methods being delegates for instance methods not being kosher), I can't exactly go as far as -Wall -Werror :D.

The worse part is I've fixed the issue by rewriting my Class methods in one class, I just have to do the other that uses the same semantics now. Pure lazyness.