Wildy71 Posted November 18, 2002 Posted November 18, 2002 Hi, I need help with a case statement (at least that's what I think I should use). I'm collecting student test results. I want to assign a total mark based on the total of some other assignments. If the total of the assignments falls between a certain range they get one mark, between other ranges then other marks should be assigned.Marks can be 1, 2, 3, 0r 4 Not sure about the syntax though. I want it to say: Term1Score = In the case that: (T1Total is >= 5 and <=13 then assign a mark of 1) or (T1Total is >=14 and <=22 then assign a mark of 2) or (T1Total >=23 and <=29 then assign a mark of 3) or (T1Total >=30 and <=36 then assign a mark of 4) or if all of these tests fail, then assign a mark of 0 If you can help me to sort this out, I'd sure appreciate it. Thanks, Paul P.S. Can you recommend any good how to FMP books for beginners.
jasonwood Posted November 18, 2002 Posted November 18, 2002 The case statement works in pairs until you get to the last part, which is your default result should should all the other tests have failed. Case (T1Total >= 5 and T1Total <= 13, 1, T1Total >= 14 and T1Total <= 22, 2, T1Total >= 23 and T1Total <= 29, 3, T1Total >= 30 and T1Total <= 36, 4, 0) Disclaimer: I just learned the "case" syntax on this forum a few days ago and have never used it! -- Jason Wood HeyWoody.com
kennedy Posted November 18, 2002 Posted November 18, 2002 Case (T1Total >= 5 and T1Total <= 13, 1, T1Total >= 14 and T1Total <= 22, 2, T1Total >= 23 and T1Total <= 29, 3, T1Total >= 30 and T1Total <= 36, 4, 0) That does exactly what was asked and will probably work fine... but the professional programmer in me always wants to make it shorter to type, easier to read, more efficient to run, and more bulletproof (e.g., what happens when you get a score of 29.5 someday in the future... or a bonus question is added and a student gets a 38... then the student gets a mark of zero [ouch])... I'd write: Case(T1Total >= 30, 4, T1Total >= 23, 3, T1Total >= 14, 2, T1Total >= 5, 1, 0) and that illustrates an additional property of Case... they are evaluated in order... so you can build on the fact that the previous tests must've failed.
Wildy71 Posted November 18, 2002 Author Posted November 18, 2002 Didn't know that! That is great. Much appreciated.
jasonwood Posted November 18, 2002 Posted November 18, 2002 kewl... I was wondering about that! Thanks!
Recommended Posts
This topic is 8111 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now