PDA

View Full Version : Easting Thing Ever, Need help with a 'Grade Calulator'



YoHoJo
05-19-2011, 04:50 AM
Written in SmallBasic.
Yeah It's ugly/sucks, I don't care It just needs to work.


TextWindow.Write("Enter Your %: ")
Grade = TextWindow.Read()
TextWindow.WriteLine("Your % Grade is " + Grade)
GradeNumber = Grade

If (0 < GradeNumber <= 59 ) Then
TextWindow.WriteLine("Your Letter Grade is F")
EndIf

If (60 <= GradeNumber < 69) Then
TextWindow.WriteLine("Your Letter Grade is D")
EndIf

If (70 <= GradeNumber < 79) Then
TextWindow.WriteLine("Your Letter Grade is C")
EndIf

If (80 <= GradeNumber < 89) Then
TextWindow.WriteLine("Your Letter Grade is B")
EndIf

If (90 <= GradeNumber < 100) Then
TextWindow.WriteLine("Your Letter Grade is A")
EndIf


The problem is that when entering any low grade, it outputs all of the higher grades also!

KingKong
05-19-2011, 05:00 AM
you must use nested ifs or the equivalent of case statements, or add boolean, so that you check for grade and change the boolean, or exit script after one of the statements is true

i luffs yeww
05-19-2011, 05:34 AM
VB has to have switch/case statements? Use those. I dunno if you need to break out like you do in some languages (with the break; function), but maybe.

cycrosism
05-19-2011, 09:02 AM
See if there is a If Between (70 and 80) function or something similar.

i luffs yeww
05-19-2011, 09:32 AM
Or make your own. All it has to do is if(Between(75, 70, 80)), and Between would just be like..


function Between(int, a, b: Integer): Boolean;
begin
if (a <= int) then
Result := b >= int;
end;

Cool Aide
05-19-2011, 12:33 PM
Try using TextWindow.ReadNumber instead of TextWindow.Read

Or you could just convert the result from TextWindow.Read to an integer.

masterBB
05-19-2011, 12:47 PM
I thought you could only use this:
If ((0 < GradeNumber) && (GradeNumber <= 59 )) Then

but I never really programmed in that language.

austin2162
05-19-2011, 03:35 PM
Or use else ifs
and rearrage from high to low
TextWindow.Write("Enter Your %: ")
Grade = TextWindow.Read()
TextWindow.WriteLine("Your % Grade is " + Grade)
GradeNumber = Grade

If (0 < GradeNumber <= 59 ) Then
TextWindow.WriteLine("Your Letter Grade is F")
ElseIF (60 <= GradeNumber < 69) Then
TextWindow.WriteLine("Your Letter Grade is D")
ElseIF (70 <= GradeNumber < 79) Then
TextWindow.WriteLine("Your Letter Grade is C")
ElseIF (80 <= GradeNumber < 89) Then
TextWindow.WriteLine("Your Letter Grade is B")
ElseIF (90 <= GradeNumber < 100) Then
TextWindow.WriteLine("Your Letter Grade is A")
EndIf
that might work

YoHoJo
05-21-2011, 02:18 AM
Or use else ifs
and rearrage from high to low
TextWindow.Write("Enter Your %: ")
Grade = TextWindow.Read()
TextWindow.WriteLine("Your % Grade is " + Grade)
GradeNumber = Grade

If (0 < GradeNumber <= 59 ) Then
TextWindow.WriteLine("Your Letter Grade is F")
ElseIF (60 <= GradeNumber < 69) Then
TextWindow.WriteLine("Your Letter Grade is D")
ElseIF (70 <= GradeNumber < 79) Then
TextWindow.WriteLine("Your Letter Grade is C")
ElseIF (80 <= GradeNumber < 89) Then
TextWindow.WriteLine("Your Letter Grade is B")
ElseIF (90 <= GradeNumber < 100) Then
TextWindow.WriteLine("Your Letter Grade is A")
EndIf
that might work

Almost... but no matter what grade I put in it says my grade is an F.
Can someone please help :], I know it's easy peasy stuff for some of you, please!

YoHoJo
05-21-2011, 09:19 PM
Still need help please.

Sex
05-21-2011, 09:37 PM
Um, would this work? http://msdn.microsoft.com/en-us/library/cy37t14y%28v=vs.80%29.aspx

Edit:
Select Case GradeNumber
Case 0 To 59
Debug.WriteLine("Your Letter Grade is F")
Case 60 To 69
Debug.WriteLine("Your Letter Grade is D")
Case 70 To 79
Debug.WriteLine("Your Letter Grade is C")
Case 80 To 89
Debug.WriteLine("Your Letter Grade is B")
Case 90 To 100
Debug.WriteLine("Your Letter Grade is A")
End Select
Edit2: Also, I think there is a flaw in your original:
ElseIF (60 <= GradeNumber < 69) Then Wouldn't it be <= 69? And also all the subsequent ifs.

YoHoJo
05-21-2011, 09:56 PM
VB and SmallBasic are related, but code from VB will not compile in SmallBasic.
I think the " If (0 < GradeNumber <= 59 ) Then " lines are just fine though... afaik.


TextWindow.Write("Enter Your %: ")
Grade = TextWindow.ReadNumber()
TextWindow.WriteLine("Your % Grade is " + Grade)


If (0 < Grade <= 59 ) Then
TextWindow.WriteLine("Your Letter Grade is F")
EndIf

If (60 <= Grade < 69) Then
TextWindow.WriteLine("Your Letter Grade is D")
EndIf

If (70 <= Grade < 79) Then
TextWindow.WriteLine("Your Letter Grade is C")
EndIf

If (80 <= Grade < 89) Then
TextWindow.WriteLine("Your Letter Grade is B")
EndIf

If (90 <= Grade < 100) Then
TextWindow.WriteLine("Your Letter Grade is A")
EndIf



Whaaa. Still same problem, no matter what grade you enter, it outputs "You Letter Grade Is" (every grade letter line)

Topdogie
05-22-2011, 12:11 AM
TextWindow.Write("Enter Your %: ")
Grade = TextWindow.ReadNumber()
TextWindow.WriteLine("Your % Grade is " + Grade)


If (90 < Grade <= 100 ) Then
TextWindow.WriteLine("Your Letter Grade is A")

ElseIf (80 <= Grade < 89) Then
TextWindow.WriteLine("Your Letter Grade is B")

ElseIf (70 <= Grade < 79) Then
TextWindow.WriteLine("Your Letter Grade is C")

ElseIf (60 <= Grade < 69) Then
TextWindow.WriteLine("Your Letter Grade is D")

ElseIf (0 <= Grade < 59) Then
TextWindow.WriteLine("Your Letter Grade is F")

Else
TextWindow.WriteLine("Cheater, grades are from 0-100%")

EndIf

should work. if not its been a while and ill have to find my old VB textbook.

YoHoJo
05-22-2011, 12:46 AM
should work. if not its been a while and ill have to find my old VB textbook.

Hey new guy thanks for trying to help me out!
Well that solved one problem, but created another.
Now for ANY grade I enter, I says I have an F! But at least it doesn't spit out all of the different options, so I'll try to tweak it a bit and see if I can get it working properly , thanks we are getting close!

Sex
05-22-2011, 12:56 AM
TextWindow.Write("Enter Your %: ")
Grade = TextWindow.ReadNumber()
TextWindow.WriteLine("Your % Grade is " + Grade)


If (Grade > 90 and Grade <= 100) Then
TextWindow.WriteLine("Your Letter Grade is A")

ElseIf (Grade > 80 and Grade <= 89) Then
TextWindow.WriteLine("Your Letter Grade is B")

ElseIf (Grade > 70 and Grade <= 79) Then
TextWindow.WriteLine("Your Letter Grade is C")

ElseIf (Grade > 60 and Grade <= 69) Then
TextWindow.WriteLine("Your Letter Grade is D")

ElseIf (Grade >= 0 and Grade <= 59) Then
TextWindow.WriteLine("Your Letter Grade is F")

Else
TextWindow.WriteLine("Cheater, grades are from 0-100%")

EndIf That works for me :o.

Edit: Fixed something.

TextWindow.Write("Enter Your %: ")
Grade = TextWindow.ReadNumber()
TextWindow.WriteLine("Your % Grade is " + Grade)


If (Grade > 90 and Grade <= 100) Then
TextWindow.WriteLine("Your Letter Grade is A")

ElseIf (Grade >= 80 and Grade <= 89) Then
TextWindow.WriteLine("Your Letter Grade is B")

ElseIf (Grade >= 70 and Grade <= 79) Then
TextWindow.WriteLine("Your Letter Grade is C")

ElseIf (Grade >= 60 and Grade <= 69) Then
TextWindow.WriteLine("Your Letter Grade is D")

ElseIf (Grade >= 0 and Grade <= 59) Then
TextWindow.WriteLine("Your Letter Grade is F")

Else
TextWindow.WriteLine("Cheater, grades are from 0-100%")

EndIf
Changed the comparison operator for first part to >=.

YoHoJo
05-22-2011, 01:07 AM
^ He did it! <3 Thanks so much!

i luffs yeww
05-22-2011, 02:03 AM
I think the important part was what I told you to do. The whole GradeNumber <= 70 and GradeNumber >= 60 thing. I think what it was doing when you had 60 <= GradeNumber <= 70 or whatever thing is that it was treating [60 <= GradeNumber] like a variable itself (a boolean, being either 0 or 1 no matter what you input ) and then doing 0 (or 1) <= 10, which is always true, no matter what!

:o I THIIIIINK that's what's happening. So I was right first! :D

Sex
05-22-2011, 02:05 AM
I was just thinking that compound inequalities like that weren't interpreted correctly.

i luffs yeww
05-22-2011, 02:06 AM
Well I think the reason is what I said. :p I dunno.

YoHoJo
05-22-2011, 04:01 AM
Yeah I think so too, thanks to both off you then! I confuse you too all the time anyways, ian, sex, iluffsyew idkwtf you all did bad stuff in past and I think you're both the same person :p.