Given an int variable named yes Count and another int variable named no Count and a char variable named response, write the necessary code to read a value from the text box text Box into response and then carry out the following:  if the character typed in is a y or a Y then increment yes Count and print out “YES WAS RECORDED”.  if the character typed in is an n or an N then increment no Count and print out “NO WAS RECORDED”.  If the input is invalid just print the message “INVALID” and do nothing else.

Given an int variable named yes Count and another int variable named no Count and a char variable named response, write the necessary code to read a value from the text box text Box into response and then carry out the following:  if the character typed in is a y or a Y then increment yes Count and print out “YES WAS RECORDED”.  if the character typed in is an n or an N then increment no Count and print out “NO WAS RECORDED”.  If the input is invalid just print the message “INVALID” and do nothing else.

LANGUAGE: Visual Basic

CHALLENGE: Given an int variable named yes Count and another int variable named no Count and a char variable named response, write the necessary code to read a value from the text box text Box into response and then carry out the following:  if the character typed in is a y or a Y then increment yes Count and print out “YES WAS RECORDED”.  if the character typed in is an n or an N then increment no Count and print out “NO WAS RECORDED”.  If the input is invalid just print the message “INVALID” and do nothing else.

SOLUTION:

response = textBox.Text
Select Case response
    Case "y"
        yesCount += 1
        System.Console.Writeline("YES WAS RECORDED")
    Case "Y"
        yesCount += 1
        System.Console.Writeline("YES WAS RECORDED")
    Case "n"
        noCount += 1
        System.Console.Writeline("NO WAS RECORDED")
    Case "N"
        noCount += 1
        System.Console.Writeline("NO WAS RECORDED")
    Case Else
        System.Console.Writeline("INVALID")
End Select


Add comment