Results 1 to 20 of 20

Thread: Easting Thing Ever, Need help with a 'Grade Calulator'

  1. #1
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default Easting Thing Ever, Need help with a 'Grade Calulator'

    Written in SmallBasic.
    Yeah It's ugly/sucks, I don't care It just needs to work.

    Code:
    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!

  2. #2
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    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

  3. #3
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    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.

  4. #4
    Join Date
    Nov 2008
    Location
    Melbourne, Australia
    Posts
    2,240
    Mentioned
    3 Post(s)
    Quoted
    11 Post(s)

    Default

    See if there is a If Between (70 and 80) function or something similar.
    Click here to find out how to get full screen without members! | Click here to check out my Ultimate Bitmap Tutorial! Edited to work with Simba! |

  5. #5
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Or make your own. All it has to do is if(Between(75, 70, 80)), and Between would just be like..

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

  6. #6
    Join Date
    Apr 2011
    Posts
    32
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Try using TextWindow.ReadNumber instead of TextWindow.Read

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

  7. #7
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    I thought you could only use this:
    If ((0 < GradeNumber) && (GradeNumber <= 59 )) Then

    but I never really programmed in that language.

  8. #8
    Join Date
    Jun 2009
    Location
    Hiding
    Posts
    160
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Or use else ifs
    and rearrage from high to low
    Simba Code:
    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
    Last edited by austin2162; 05-19-2011 at 03:40 PM.
    ~Austin~

  9. #9
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Quote Originally Posted by austin2162 View Post
    Or use else ifs
    and rearrage from high to low
    Simba Code:
    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!

  10. #10
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Still need help please.

  11. #11
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Um, would this work? http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx

    Edit:
    Code:
    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.
    Last edited by Sex; 05-21-2011 at 09:42 PM.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  12. #12
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    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)
    Last edited by YoHoJo; 05-21-2011 at 10:23 PM.

  13. #13
    Join Date
    May 2011
    Location
    Middle of a corn field
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

  14. #14
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Quote Originally Posted by Topdogie View Post
    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!

  15. #15
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Code:
    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 .

    Edit: Fixed something.
    Code:
    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 >=.
    Last edited by Sex; 05-22-2011 at 12:59 AM.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  16. #16
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    ^ He did it! <3 Thanks so much!

  17. #17
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    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!

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

  18. #18
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    I was just thinking that compound inequalities like that weren't interpreted correctly.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  19. #19
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Well I think the reason is what I said. I dunno.

  20. #20
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    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 .

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •