help with loops

prozac

New member
Joined
Apr 27, 2007
Messages
3
Programming Experience
Beginner
i have some code as follows, where i am trying to loop a series of input boxes for the user to place marks for their assignments. this all happens when i click a button to enter marks for their assignments.

VB.NET:
Dim markIn As Integer
Dim total As Integer
Dim max As Integer
Dim grade As Integer
Dim mark As Integer
Dim mposs As Integer
 
max = 100
 
Do
markIn = InputBox("enter your mark for an assignment")
total = InputBox("enter the total marks possible for this assignment")
mark = Val(markIn)
mposs = Val(total)
Loop Until total >= max Or markIn > total 
 
grade = Val(mark)
uiLabel6.Text = Val(grade)
uiLabel7.Text = Val(mposs)
 
 
If grade < 50 Then
MsgBox("you recieved a Fail")
ElseIf grade < 65 Then
MsgBox("you recieved a Pass")
ElseIf grade < 75 Then
MsgBox("you recieved a Credit")
ElseIf grade < 85 Then
MsgBox("you recieved a Distinction")
ElseIf grade > 85 Then
MsgBox("you recieved a High Distinction")
Else
MsgBox("Error")
End If
now what i cant get to happen no matter what i try is for each mark they put and and for each total, i dont know how to make them all add up in a textbox. Say they enter 45 for their mark, then 50 for marks possible for the assignment, then 45 again and 50 again, the program should stop as they have reached 100 then give them a high distinction. But this cannot happen as the code is not storing the 50 then the 50 again to add up to 100 then stop. It only goes 50 is not one hundred so go again. Can anyone help me here?
 
VB.NET:
Dim NumAssign As Integer = CInt(InputBox("Total number of assignments:"))
Dim Mark(NumAssign) As Integer
Dim CurrAssign As Integer

Do While CurrAssign <= NumAssign
  CurrAssign += 1
  Mark(CurrAssign) = Cint(InputBox("Enter marks for Assignment " & CurrAssign & ":"))
  Mark(0) += Mark(CurrAssign)
Loop


Select Case Mark(0)

  Case Is <= 50
    Messagebox.show("You've Failed")
  Case Is <= 65
    Messagebox.Show("You've Passed")
  Case Is <= 75
    Messagebox.Show("You've Recieved a Credit")
  Case Is <= 85
    Messagebox.Show("You've Recieved a Distinction")
  Case Else
    Messagebox.Show("You've recieved a High Distinction")
End Select

or something like this, I don't have the IDE with me right now to test it
 
Say they enter 45 for their mark, then 50 for marks possible for the assignment, then 45 again and 50 again, the program should stop as they have reached 100 then give them a high distinction. But this cannot happen as the code is not storing the 50 then the 50 again to add up to 100 then stop. It only goes 50 is not one hundred so go again. Can anyone help me here?

You clearly understand how the program is to flow, what I recommend for you is to write the flow into comments first, then put in the code behind the comments.. THink of it like learning french. WHen youre new, you assemble a sentence in English, then translate it to French. Eventually, you start to think in French. Right now youre still at that translate phase.. so help yourself out, write comments, translate them to vb, you get a nicely commented program, and more marks for it
 
I dont do homework, but I'll walk through it with you. Write the theory in comments. I'll start you off:

VB.NET:
'start a loop that will continuously ask for details
 
'ask for the first name and remember it
 
'ask for the surname and remember it
 
...
 
yea man, thanks alot for the help guys, and I GOT IT!!, WOOHOO, cyas later, u may close or delete this or whatever u want. really really appreciate the help guys and girls. :D, took me ages but eventually i got it done.
 
Back
Top