HomerJaySimpson Posted November 24, 2004 Posted November 24, 2004 Alright i've been trying to figure out why im getting thie else without if error for about a week now and can't find anything on the interweb. So it's time to ask someone who will know... Here's the code i have so far...I have tried putting brackets in every order i can imagine but i ended up taking them out. I know the {} is probably why im getting errors but i can't figure it out...Please help import InOut; class Test1 { public static void main (String[]args) { String memType, insureType; String name, handicap, full, fiveDay, social; int count; int memCategory, insurePremium, annualSub; for (count=1; count <=9; count=count+1) { name=InOut.readLine(); handicap=InOut.readLine(); memCategory=InOut.readInt(); insurePremium=InOut.readInt(); if (memCategory <= 1000) { annualSub = 200+insurePremium; memType="Full"; full=full+1; else if (memCategory <= 1500) annualSub=120 +insurePremium; memType="fiveDay"; fiveDay=fiveDay+1; else annualSub=40; memType="social"; social=social+1; } if (insurePremium <= 15) { insureType="Comprehensive"; else if (insurePremium <=10); insureType="3rd party injury"; else insureType="None"; } System.out.println ("Name Handicap Membership Annual Subscription"); System.out.println (""+name+"\t"+handicap+"\t"+memType+"\t"+annualSub); } System.out.println ("full fiveDay social"); System.out.println (""+full+"\t"+fiveDay+"\t"+social); } } Quote Share this post Link to post Share on other sites More sharing options...
hardnrg Posted November 24, 2004 Posted November 24, 2004 else if (insurePremium <=10); insureType="3rd party injury"; the semicolon at the end of the else-if line ACTUALLY i'm pretty sure the format goes like this: if (condition) { statement1; statement2; } else if (condition) { statement3; statement4; } else { statement5; your_mum; } Quote Share this post Link to post Share on other sites More sharing options...
HomerJaySimpson Posted November 24, 2004 Posted November 24, 2004 (edited) Edited November 24, 2004 by HomerJaySimpson Quote Share this post Link to post Share on other sites More sharing options...
hardnrg Posted November 24, 2004 Posted November 24, 2004 ah .. erm, i don't think you can have "else if"... i think it's like if blah else if blah2 else blah3 maybe... it's been a while dangit... that's just the same... bah! Quote Share this post Link to post Share on other sites More sharing options...
HomerJaySimpson Posted November 24, 2004 Posted November 24, 2004 Yeah thats what it said on my pseudocode, but do i put it as: else if { (whatever) } I've already tried this way and still keep getting the dang else without if error... Quote Share this post Link to post Share on other sites More sharing options...
hardnrg Posted November 24, 2004 Posted November 24, 2004 please tell me which else is the one causing the problem (should say in the debug error) Quote Share this post Link to post Share on other sites More sharing options...
Kamikaze_Badger Posted November 24, 2004 Posted November 24, 2004 http://www.scs.leeds.ac.uk/pfaf/design/basicjava.html Quote Share this post Link to post Share on other sites More sharing options...
HomerJaySimpson Posted November 24, 2004 Posted November 24, 2004 Thanx guys....It's too late to start reading, so ill just bring it in to college tomorrow and find out where i went wrong Quote Share this post Link to post Share on other sites More sharing options...
cchalogamer Posted November 24, 2004 Posted November 24, 2004 do something like this if (condition) { } if (condition) { } else (condition) { } If one of the first 2 things id true it will do them (both if both are true) then if neither of the 1st 2 are ture it does the else if you need it to do it differently (as in only choosing one option and never beign able to do 2) use nested ifs Im tryign to compile your code, but i dont personally use the InOut setup to get input. Im getting errors on your import line for that idk. Ok other than InOut related errors, i have this that gives no if else problems, it was a mix of ; and {} errors. import InOut; class Test1 { public static void main (String[]args) { String memType, insureType; String name, handicap, full, fiveDay, social; int count; int memCategory, insurePremium, annualSub; for (count=1; count <=9; count=count+1) { name=InOut.readLine(); handicap=InOut.readLine(); memCategory=InOut.readInt(); insurePremium=InOut.readInt(); if (memCategory <= 1000) { annualSub = 200+insurePremium; memType="Full"; full=full+1; if (memCategory <= 1500) { annualSub=120 +insurePremium; memType="fiveDay"; fiveDay=fiveDay+1; } else { annualSub=40; memType="social"; social=social+1; } } if (insurePremium <= 15) { insureType="Comprehensive"; if (insurePremium <=10) insureType="3rd party injury"; else insureType="None"; } System.out.println ("Name Handicap Membership Annual Subscription"); System.out.println (""+name+"\t"+handicap+"\t"+memType+"\t"+annualSub); } System.out.println ("full fiveDay social"); System.out.println (""+full+"\t"+fiveDay+"\t"+social); } } Quote Share this post Link to post Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.