Alice Community Problems with If/Else
 User Name Remember Me? Password

 Thread Tools Display Modes
 Problems with If/Else
 CaptainLizard Junior Member   Status: Offline Posts: 11 Join Date: Aug 2012 Problems with If/Else - 11-14-2012, 09:46 AM So I'm doing the race horse exercise (Chapter 8-1 Exercise 1). I have created a very long IF/Else statement to check which horse is ahead of the others. It works for the most part but when more than one horse crosses the line, usually horse number one wins. Now I've watched the variables on many different runs and I have come to the conclusion that when Alice asks If Distance1 < Distance2 that it is taking the absolute value of these numbers. For example, one of my runs had horse1 with a distance of -0.04 and horse2 with a distance of -1.24. Logically, horse2 won because it is farther than horse1, but the program keeps picking horse1. This is not just limited to horse1. The program seems to be breaking the tie as long as the distance is between 0.49 and -0.99. My question is how do I get around this? Any help is appreciated Last edited by CaptainLizard; 11-14-2012 at 09:56 AM.
CaptainLizard
Junior Member

Status: Offline
Posts: 11
Join Date: Aug 2012
11-14-2012, 09:46 AM

Forgot the program. It is attached here.
Attached Files
 horse.a2w (1.63 MB, 16 views)

CaptainLizard
Junior Member

Status: Offline
Posts: 11
Join Date: Aug 2012
11-14-2012, 10:17 AM

I rewrote the If/Else (found in the raceHorseGame.Winner method so you don't have to go searching for it) and it seems to be more consistent about picking the correct winner, but still seems to be having the same issue.

But in remaking the IF/Else, I've come to a different conclusion. It seems that it is disregarding the If distance1 < distance2 and just looking for if distance1 < 0.5.

Attached is the modified version of the program.
Attached Files
 race.a2w (1.56 MB, 17 views)

 AnyBibi Guest   Status: Posts: n/a 11-15-2012, 11:01 AM I'm looking at your problem, you can have the wrong times.I will reply you soon ..................... phim, phim tinh cam, Phim hay, xem phim
 CaptainLizard Junior Member   Status: Offline Posts: 11 Join Date: Aug 2012 11-26-2012, 10:09 AM Well, I've seemed to have found a solution on my own. the problem was I was using "or" instead of "and." For example, I had "If either distance1 < distance2 or distance1 < distance3, or both" when I should've had "If distance1 < distance2 and distance1 < distance3." Makes a world of a difference.

 Tags alice 2.2 horse race

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops     Alice Player and VR General Discussion     Questions and Comments     The Lounge