• Help with a Program (Finding Average, Highest, and Lowest Numbers)
    7 replies, posted
I'm in Programming 1, so I am confused as hell. I managed to get the password input set up correctly, so that doesn't need any editing. I HAD the average set up correctly, then changed it and cannot remember how I had it set up previously. I am including the instructions and what I have so far, please feel free to give me advice and/or tips on where to go from here. VISUAL BASIC 2008 is the suite being used. Again, Part I is already complete. [quote] Program #11 - Password and Bowling Scores Programming I I. Password Program Create a password program that prompts the user, with an InputBox, for their password before they see the form. Dim the password as string and assign it any string of your choosing. The user should get three tries to enter the password correctly. If they do enter it correctly display the form (with the bowling program). If they enter it incorrectly three times, display a MsgBox telling them and end the program. Use a Do Loop. II. Bowling Scores Create a program allows the user to enter bowling scores. The program will display the high score, low score and average score. The "Enter Scores" button should use a Do Loop and an InputBox to allow the user to enter as many scores as they want. They should be instructed to enter a flag (of your choosing) when they are done. The "Statistics" button should display the high score, low score, and the average score in a label on the form. If the "Enter scores" button is clicked again the statistics should be reinitialized, and calculated for the new scores entered only. [/quote] At first I had it set up to ask how many scores the user will be entering, but after re-reading the lesson that is not correct, it is supposed to accept scores until the user types in the flag number. [code] Public Class Form1 Dim score As Integer Dim numscores As Integer Dim total As Single Dim average As Single Dim x As Single Dim highest As Integer Dim lowest As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lblhigh.Text = "" lbllow.Text = "" lblaverage.Text = "" Dim actualpassword As String Dim password As String actualpassword = "orangegophers" Do password = InputBox("Please enter your password.") If password = actualpassword Then MsgBox("Thank you, clearance granted.") Else password = InputBox("Please enter your password.") If password = actualpassword Then MsgBox("Thank you, clearance granted.") Else password = InputBox("Please enter your password.") If password = actualpassword Then MsgBox("Thank you, clearance granted.") Else MsgBox("Locking you out of the system....") End End If End If End If Loop Until password = "orangegophers" End Sub Private Sub btnscores_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnscores.Click numscores = Val(InputBox("How many scores will you be entering?")) Do Until score = numscores score = Val(InputBox("Enter scores.")) total = score + score Loop average = total / numscores End Sub Private Sub btnstats_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstats.Click lbllow.Text = lowest lblhigh.Text = highest lblaverage.Text = average End Sub End Class [/code]
use a loop, do the inputbox, and exit if they type 'done' or something
I've never used VB.NET, so bear with me and see if this works: [code]Imports Microsoft.VisualBasic Public Class Form1 Dim score As Integer Dim numscores As Integer Dim total As Single Dim average As Single Dim x As Single Dim highest As Integer Dim lowest As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lblhigh.Text = "" lbllow.Text = "" lblaverage.Text = "" Dim actualpassword As String Dim attempts As Integer Dim password As String actualpassword = "orangegophers" Do password = InputBox("Please enter your password.") If password = actualpassword Then MsgBox("Thank you, clearance granted.") Exit Do Else attempts = attempts + 1 If attempts >= 3 Then MsgBox("Locking you out of the system....") End End If End If Loop Until password = "orangegophers" End Sub Private Sub btnscores_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnscores.Click Do Until score = numscores Dim ret As String ret = InputBox("Enter scores, leave empty to indicate end of sequence") If ret = "" Then Exit Do numscores = numscores + 1 score = Val(ret) total = total + score If score > highest Then highest = score ElseIf score < lowest Then lowest = score End If Loop average = total / numscores End Sub Private Sub btnstats_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstats.Click lbllow.Text = lowest lblhigh.Text = highest lblaverage.Text = average End Sub End Class[/code]
[QUOTE=cas97;18051335]use a loop, do the inputbox, and exit if they type 'done' or something[/QUOTE] I know that this is what I have to do, but I do not know where to go from there. [editline]08:10PM[/editline] [QUOTE=voodooattack;18051508]I've never used VB.NET, so bear with me and see if this works: [code]Imports Microsoft.VisualBasic Public Class Form1 Dim score As Integer Dim numscores As Integer Dim total As Single Dim average As Single Dim x As Single Dim highest As Integer Dim lowest As Integer Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lblhigh.Text = "" lbllow.Text = "" lblaverage.Text = "" Dim actualpassword As String Dim attempts As Integer Dim password As String actualpassword = "orangegophers" Do password = InputBox("Please enter your password.") If password = actualpassword Then MsgBox("Thank you, clearance granted.") Exit Do Else attempts = attempts + 1 If attempts >= 3 Then MsgBox("Locking you out of the system....") End End If End If Loop Until password = "orangegophers" End Sub Private Sub btnscores_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnscores.Click Do Until score = numscores Dim ret As String ret = InputBox("Enter scores, leave empty to indicate end of sequence") If ret = "" Then Exit Do numscores = numscores + 1 score = Val(ret) total = total + score If score > highest Then highest = score ElseIf score < lowest Then lowest = score End If Loop average = total / numscores End Sub Private Sub btnstats_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnstats.Click lbllow.Text = lowest lblhigh.Text = highest lblaverage.Text = average End Sub End Class[/code][/QUOTE] Thanks for trying to help, but I ran the program with the changes you made and still no tamale. The Input Box for the scores does not show up at all.
[QUOTE=Ca5bah;18051803]I know that this is what I have to do, but I do not know where to go from there. [editline]08:10PM[/editline] Thanks for trying to help, but I ran the program with the changes you made and still no tamale. The Input Box for the scores does not show up at all.[/QUOTE] Oh, remove "Until score = numscores", forgot that, sorry.
VB makes me go "what the fuck"
[QUOTE=By The Way;18053369]VB makes me go "what the fuck"[/QUOTE] I second this. After I learned it last year and transitioned into C++ at school this trimester, I couldn't go back. Too messy and really wordy in my opinion.
[QUOTE=voodooattack;18051907]Oh, remove "Until score = numscores", forgot that, sorry.[/QUOTE] Thanks so much.
Sorry, you need to Log In to post a reply to this thread.