我的任务是创建一个Visual Basic控制台脚本,连续5次要求用户在数组中输入一个数字(销售数字为数千),然后将这些结果显示为一种计数图表。 / p>
例如数据:销售额(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
我只是不确定如何将数组中的整数值更改为一定数量的单个字符。
答案 0 :(得分:3)
For Each i As Integer In Sales
Console.WriteLine(New String("+"c, i))
Next i
答案 1 :(得分:1)
不会添加一个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