Question # 1:
Ask the user to enter two different numbers. Print all the numbers between the two values they enter.

Question # 2:
Allow the user to enter as many as positive numbers as they wish, and enter zero to indicate they have finished. Then display the number of even values and number of odd values entered by the user. Hint: use the MOD operator to work out weather a number is odd or even.

Question # 3:
Allow the user to enter the password “secret” up to three attempts. Inform the user which attempt they are currently on (1, 2, and 3). Inform the user if the password is correct if they get it, otherwise inform the user the password is incorrect and exit the program.

Question # 4:
Ask the user to “Y”, “N”, “Q” (Quit) in response to this question. “Has” the user passed their driving test?” Continue asking this question until the user answers “Q”. Output the number and percentage of people who have passed their test.

We won;t just do the whole thing for you here at DaniWeb. You must at least attempt to do it yourself and post your code when you get stuck then we will help you get it working.

These questions are obviously designed to demonstrate the basic constructs of structured programming Input, looping and decision making and outputing the result.

the code for third question is this


Private Sub Command1_Click()
If Text1.Text = "secret" Then
MsgBox "password is correct"
ElseIf Text1.Text <> "secret" Then
MsgBox "password is incorrect 1st time"
ElseIf Text1.Text <> "secret" Then
MsgBox "password is incorrect 2nd time"
ElseIf Text1.Text <> "secret" Then

MsgBox "password is incorrect 3rd time"

End If
End Sub

the code for question no. 4 is


Private Sub Command1_Click()
If Text1.Text = "Y" Then
MsgBox " yes the user has passed their driving test"
ElseIf Text1.Text = "N" Then
MsgBox " no the user has not passed the driving test"
ElseIf Text1.Text = "Q" Then
End
End If
End Sub

Ok I think in three what they want you to do is a global variable :

Dim guesses As Integer 
guesses = 3

Private Sub Command1_Click()
    If Text1.Text = "secret" Then
        MsgBox "password is correct"
        Exit Sub
    Else
        guesses = guesses - 1
        MsgBox "password is incorrect. " & guesses & " remaining"
    End If

    If guesses = 0 Then 
        Me.Unload
    End If

End Sub

You should ba able to use similar idea for Q4 keep count of answers in two global integer variables failed and passed, increment them as per each yes and no answer. Add a label to your form and set it's text property to something like Label.text = failed & " People failed, " & passed & " People passed."

I've not got VB6 anymore (I assume that's what you're using as your in Vb forum) So I can't check this code, if you get any errors post them word for word and I'll help best I can. Bear with me I am in a full time job and busy busy.

hi thnx for the reply
first of all yes, i m using the vb 6 version.
now the problem related to this program is that
the constant "guesses" is not accepting the value 3
and the whole program is perfect but the only error is it is inot stoping on the 3 attempt.

Is the message box with guesses remaining always say 3 remaining? or what? can you post your code as it now stands please? I'll see if I can work out your problem.

hi thnx for the reply
first of all yes, i m using the vb 6 version.
now the problem related to this program is that
the constant "guesses" is not accepting the value 3
and the whole program is perfect but the only error is it is inot stoping on the 3 attempt.

Your new at this aren't you.:) come on paste the code I wanna fix it.

Dim guesses As Integer (this is written in the declaration event)

Private Sub Command1_Click()
If Text1.Text = "secret" Then
MsgBox "password is correct"
Exit Sub
Else
guesses = guesses - 1
MsgBox "password is incorrect. " & guesses & " remaining"
End If

If guesses = 0 Then
End
End If

End Sub

now when i enter the wrong password it gives me msg box in which it is written " password is incorrect , -1 remaining"

then on the second attempt "password is incorrect,-2 remaining"

and keeps on increasing the remaining no.
i want that when i make a third attempt the program terminates.

Dim guesses As Integer

Private Sub Command1_Click()
If Text1.Text = "secret" Then
MsgBox "password is correct"
Exit Sub
Else
guesses = guesses - 1
MsgBox "password is incorrect. " & guesses & " remaining"
End If

If guesses = 0 Then
End
End If

End Sub

hi man i m done with this problem i have solved it
thanks a lot for helping me so much.
i have done Q-1 as well
but still question -2 and question -4 left behind

Hi Sweety,

Solution For Q-2 :

Private Sub cmdOddEven_Click()
Dim NOdd As Long
Dim NEven As Long
Dim TNo As Long
Dim NEvenStr As String
Dim NOddStr As String
NEvenStr = ""
NOddStr = ""
NOdd = 0
NEven = 0
Do
TNo = Val(InputBox("Enter The Number", "Check Odd Even", 0))
If TNo <> 0 Then
If TNo Mod 2 = 0 Then
NEven = NEven + 1
NEvenStr = NEvenStr & TNo & " ; "
Else
NOdd = NOdd + 1
NOddStr = NOddStr & TNo & " ; "
End If
End If
Loop Until TNo = 0
MsgBox "Number Of Odd : " & NOdd & vbCrLf & "They Are : " & NOddStr
MsgBox "Number Of Evens : " & NEven & vbCrLf & "They Are : " & NEvenStr
End Sub


Solution For ur Q-4 :

Private Sub cmdDriveTest_Click()
Dim NYes As Long
Dim NNo As Long
Dim i As Integer
Dim TStr As String
Dim PassPerc As Currency
'
NYes = 0
NNo = 0
PassPerc = 0
'
TStr = "Have You Passes Driving Test"
TStr = TStr & vbCrLf & "Click Yes : If Passed"
TStr = TStr & vbCrLf & "Click No : If Not Passed"
TStr = TStr & vbCrLf & "Click Cancel : To Finish"
Do
i = MsgBox(TStr, vbQuestion + vbYesNoCancel, "Drive Test Data Analysis")
If i = vbYes Then
NYes = NYes + 1
ElseIf i = vbNo Then
NNo = NNo + 1
End If
Loop Until i = vbCancel
If (NYes + NNo) <> 0 Then
PassPerc = (NYes * 100) / (NYes + NNo)
PassPerc = Format(PassPerc, "0.00")
End If
MsgBox "Number of People Passed : " & NYes
MsgBox "Number of People Failed : " & NNo
MsgBox "Total Number of People Taken Test: " & (NNo + NYes)
MsgBox "Passing Percentage : " & Format(PassPerc, "0.00")
End Sub

U can mail me if u have any doubts

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.