Visual basic将数组整数(x)转换为单个字符的x数量



我的任务是创建一个Visual Basic控制台脚本,该脚本要求用户连续5次向数组中输入数字(销售额以千计),然后将这些结果显示为一种统计图。

例如数据:销售额(10、7、12、5、15)输出将是

2008:++++++++++
2009:+++++++
2010:++++++++++++
2011:+++++
2012:+++++++++++++++

到目前为止,我的代码:

Module Module1
Sub Main()
    Dim sales(4) As Integer
    Dim index As Integer
    Dim year As Integer

    For index = 0 To 4
        Console.Write("Enter your sales numbers (in thousands): ")
        sales(index) = Console.ReadLine()
    Next
    year = 2007
    For index = 0 To 4
        year = (year + 1)

---不确定这里的代码---

        Console.WriteLine(year & ": " & ????????)
    Next
    Console.ReadLine()
End Sub
End Module

我只是不确定如何将数组中的整数值更改为单个字符的特定数量。

For Each i As Integer In Sales
    Console.WriteLine(New String("+"c, i))
Next i

添加一个for来显示几次"-"就足够了吗?

比如:

For index = 0 To 4
    year = (year + 1)
    Console.Write(year & ": ")
    ' Display as much "-" as there are sales
    For s = 1 to sales(index)
        Console.Write("-")
    Next s
    Console.WriteLine("") 'Next line
Next index

最新更新