Simple console programme Help with VB.Net

Bakerdude

New member
Joined
Nov 14, 2006
Messages
1
Programming Experience
Beginner

#############################
############EDIT##############
#############################


*Within the five minuets that I posted this thread I managed to figure it out, start with >=80 then >= 60 then >=40 and it works*


#############################
############EDIT##############
#############################

Hi

I've been given a small assignment to do for college. What I have to do is create a programme that reads a user number input and then gives a result relavent to that input. We were told to create a programme that would tell a user if they passed a course depending on their grade. For example if the user enetered 1 the programme would tell them they failed, if they enter 40 upwards it would tell them they got a PASS grade, if they enter 60 upwards it would tell them they got a MERIT grade and 80 upwards it would return DISTINCTION GRADE.

I got the programme to work if the user enters a number less then 40, it returns the right response. If the user eneters anything more then 40 it also leaves the right response. However when you try to enter anything above 60 the programme gives a response as if you entered something above 40 and not the desired response if you enter 60+

Here is my code.

VB.NET:
Imports System.Console 

Public Class Marks

       Shared Sub Main()

       Dim Result As Decimal 

    Writeline("    *~*Did you pass your course?*~*") 
    Writeline("*This prgramme will work it out for you*")
    Writeline(" ")

    Writeline("Please enter your final score: ")
    
    Result = Readline()

            If (Result >=40)             
            Writeline("Congratulations you got a PASS grade")
            Readline()

            ElseIf (Result >=60)             
            Writeline("Congratulations you got a MERIT grade")
            Readline()
            
            ElseIf (Result >=80)
            Writeline("Congratulations you got a DISTINCTION grade")'
            Readline()

            Else         
            Writeline("Sorry you FAILED") 
            Readline()
    
            End If 
                    
            
        End Sub

End Class
I've tried a number of other methods such as:

VB.NET:
If (Result >=40 <=59)             
            Writeline("Congratulations you got a PASS grade")
            Readline()
However with this code if the user enters anything less then 40 it tells them they passed. Iv'e tried using >39 which still gives the same response as =>40.

I only have a limited knowledge of VB.Net so I can't think of any other ways.

Thanks for any help in advance.
 
Last edited:
Now its works........

VB.NET:
[COLOR=#0000ff]
Imports[/COLOR] System.Console
[COLOR=#0000ff]Public[/COLOR] [COLOR=#0000ff]Class[/COLOR] Marks1
[COLOR=#0000ff]Shared[/COLOR] [COLOR=#0000ff]Sub[/COLOR] Main()
[COLOR=#0000ff]Dim[/COLOR] Result [COLOR=#0000ff]As[/COLOR] [COLOR=#0000ff]Decimal
[/COLOR]WriteLine([COLOR=#800000]" *~*Did you pass your course?*~*"[/COLOR])
WriteLine([COLOR=#800000]"*This prgramme will work it out for you*"[/COLOR])
WriteLine([COLOR=#800000]" "[/COLOR])
WriteLine([COLOR=#800000]"Please enter your final score: "[/COLOR])
Result = ReadLine()
[COLOR=#0000ff]If[/COLOR] (Result >= 40 [COLOR=#0000ff]And[/COLOR] Result < 60) [COLOR=#0000ff]Then
[/COLOR]WriteLine([COLOR=#800000]"Congratulations you got a PASS grade"[/COLOR])
ReadLine()
[COLOR=#0000ff]ElseIf[/COLOR] (Result >= 60 [COLOR=#0000ff]And[/COLOR] Result < 80) [COLOR=#0000ff]Then
[/COLOR]WriteLine([COLOR=#800000]"Congratulations you got a MERIT grade"[/COLOR])
ReadLine()
[COLOR=#0000ff]ElseIf[/COLOR] (Result >= 80) [COLOR=#0000ff]Then
[/COLOR]WriteLine([COLOR=#800000]"Congratulations you got a DISTINCTION grade"[/COLOR]) [COLOR=#008000]'
[/COLOR]ReadLine()
[COLOR=#0000ff]Else
[/COLOR]WriteLine([COLOR=#800000]"Sorry you FAILED"[/COLOR])
ReadLine()
[COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]If
 
[/COLOR][COLOR=#0000ff]End[/COLOR] [COLOR=#0000ff]Sub
End[/COLOR] [COLOR=#0000ff]Class
[/COLOR]

Use This........ It works
 
Select Case can also be useful here:
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] result [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]CInt[/COLOR][/SIZE][SIZE=2](Console.ReadLine)[/SIZE]
[SIZE=2][COLOR=#0000ff]Select [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] result[/SIZE]
[SIZE=2][COLOR=#0000ff]Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] < 40[/SIZE]
[SIZE=2]  Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"Sorry you FAILED"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 40 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] 59[/SIZE]
[SIZE=2]  Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"Congratulations you got a PASS grade"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 60 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] 79[/SIZE]
[SIZE=2]  Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"Congratulations you got a MERIT grade"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Is [/COLOR][COLOR=black]>= 80[/COLOR][/SIZE]
[SIZE=2]  Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"Congratulations you got a DISTINCTION grade"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]
 
Back
Top