Visual Basic - 计算字符的用户输入总数



我目前正在大学学习使用Visual Basic进行编程,因此我仍然是一个初学者,仍然不知道很多功能。有人可以告诉我如何做到这一点,我真的很困惑。

调整程序,

使用户输入"N"时程序显示"输入的钻石数量为:",钻石数量

基本上,计算用户输入 N 时输入 Y 的次数。很难解释,这是我必须调整的代码:

Sub Main()
    Dim Weight As Integer
    Console.WriteLine("Enter the weight of your diamond in grams")
    Weight = Console.ReadLine
    Console.WriteLine("This diamond costs : " & Weight * 350)
    Console.WriteLine("Would you like to price another Y/N?")
    Dim UserValue As Char = Console.ReadLine
    If UserValue = "Y" Then
        While UserValue = "Y"
            Console.WriteLine("Enter the weight of the new diamond in grams")
            Weight = Console.ReadLine
            Console.WriteLine("This diamond costs : " & Weight * 350)
            Console.WriteLine("Would you like to price another Y/N?")
            Console.ReadLine()
        End While
    End If
    UserValue = "N"
    Console.WriteLine("The total number of diamonds entered is : ")
End Sub
我要

做的是调暗一个整数,例如,y计算多少个Y并在用户返回"Y"时分配以下内容

y = y + 1

这样当用户最终给出"N"时,你说

Console.WriteLine(y)

简单来说。

最新更新