This program returns a letter grade when a test score is entered.
The program that my modified version is based on uses A=90 or above, B=80 and above, etc. I changed it to display A+, A-, etc. by adding in additional ElseIf statements. I also had to change the Function's type from Char to String.
Function LetterGrade(ByVal score As Double) As String
If score >= 97 Then
Return "A+"
ElseIf score >= 93 Then
Return "A"
ElseIf score >= 90 Then
Return "A-"
Thursday, May 10, 2012
Wednesday, May 9, 2012
Add Coins
I made a very simple mishap here. I used two equal signs and wrote total = (quart * 0.25) + (dime * 0.1) = (nick * 0.05) + (penny * 0.01), instead of total = (quart * 0.25) + (dime * 0.1) + (nick * 0.05) + (penny * 0.01) with only one equal sign.
CD DVD Tips
This was the code I wrote originally:
Private Sub btnTip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTip.Click
Call Message(Me.lblTip)
End Sub
'After button has been clicked, a random number will be chosen that represents one of the three tips
'post: the tip will show up in the label
Sub Message(ByRef lblMessage As Label)
Randomize()
Dim tipNumber As Integer
tipNumber = Int(3 * Rnd()) + 1
Select Case tipNumber
Case 1
lblMessage.Text = "Handle CD/DVDS by the center hole or by the edges."
Case 2
lblMessage.Text = "Keep CD/DVDs away from extreme temperatures and moisture."
Case 3
lblMessage.Text = "Store discs in a jewel case or sleeve to prevent scratches."
End Select
This is the updated version with parameters based on TestRndIntFunction
Dim lowNum As Integer = 1
Dim highNum As Integer = 3
Dim chosenNum As Integer
Call RndInt(lowNum, highNum, chosenNum)
If chosenNum = 1 Then
Me.lblTip.Text = "Handle CD/DVDS by the center hole or by the edges."
ElseIf chosenNum = 2 Then
Me.lblTip.Text = "Keep CD/DVDs away from extreme temperatures and moisture."
Else
Me.lblTip.Text = "Store discs in a jewel case or sleeve to prevent scratches."
End If
End Sub
'After button has been clicked, a random number will be chosen that represents one of the three tips
'post: the tip will show up in the label
Sub RndInt(ByVal firstNum As Integer, ByVal secondNum As Integer, ByRef thirdNum As Integer)
Randomize()
thirdNum = ((secondNum - firstNum + 1) * Rnd()) + firstNum
Tuesday, May 1, 2012
Acronym - unresolved
I haven't figured this out yet:
the original mess:
Dim numEntered As String
Dim numWords As Integer
Dim acronym As String
Dim wordEntered As String
Dim letter As String
Dim fullWord As String
numEntered = InputBox("Number of words", "Enter the number of words in the acronym")
numWords = Val(numEntered)
fullWord = Nothing
For count As Integer = 1 To numWords
wordEntered = InputBox("Word", "Enter the word.")
wordEntered.ToUpper()
letter = wordEntered.Chars(0)
letter = fullWord.Chars(count)
acronym = Nothing
acronym = String.Concat(acronym, letter)
Next count
the original mess:
Dim numEntered As String
Dim numWords As Integer
Dim acronym As String
Dim wordEntered As String
Dim letter As String
Dim fullWord As String
numEntered = InputBox("Number of words", "Enter the number of words in the acronym")
numWords = Val(numEntered)
fullWord = Nothing
For count As Integer = 1 To numWords
wordEntered = InputBox("Word", "Enter the word.")
wordEntered.ToUpper()
letter = wordEntered.Chars(0)
letter = fullWord.Chars(count)
acronym = Nothing
acronym = String.Concat(acronym, letter)
Next count
Name Backwards
I made this one far too complicated.
I tried to split up the program to do the first name and last name separately. I also had the characters picked out one by one and... things just got really messy.
The new and improved code:
Dim origName As String = Me.txtName.Text
Dim lengthName As Double = origName.Length
Dim backName As String = Nothing
Dim currentLetter As String
For count As Integer = (lengthName - 1) To 0 Step -1
currentLetter = origName.Chars(count)
backName = String.Concat(backName, currentLetter)
Next count
Me.lblBackwards.Text = backName
Wednesday, April 11, 2012
Remove String
Today's mishap of the day:
Dim newSentence As Char
versus
Dim newSentence As String
That was all it took to make the program mess up. Head-shaking. The program's objective is to, given a sentence and a phrase to remove from that sentence, remove that phrase. For example, if you type "I dislike vegetables," and remove "dis," the new statement should read "I like vegetables." The error above meant only "I" showed up in the new statement.
Dim newSentence As Char
versus
Dim newSentence As String
That was all it took to make the program mess up. Head-shaking. The program's objective is to, given a sentence and a phrase to remove from that sentence, remove that phrase. For example, if you type "I dislike vegetables," and remove "dis," the new statement should read "I like vegetables." The error above meant only "I" showed up in the new statement.
Tuesday, April 10, 2012
CD Calculator
This calculates the number of years for an initial investment to accumulate (thanks to interest) to a certain amount based on given initial amount, final amount, and interest rate.
A few things I learned from this:
a) When setting up a counter, define an initial value for the counter.
years=0
years += 1
b) Argh! Use decimal format for interest rate. It's much more logical.
c) Check signs (ie greater than versus less than).
A few things I learned from this:
a) When setting up a counter, define an initial value for the counter.
years=0
years += 1
b) Argh! Use decimal format for interest rate. It's much more logical.
c) Check signs (ie greater than versus less than).
Subscribe to:
Posts (Atom)