2012-03-31 33 views
0

我的任務是創建一個Visual Basic控制檯腳本,要求用戶連續5次向數組中輸入一個數字(銷售數字爲千),然後將這些結果顯示爲一種理貨圖表。Visual Basic將數組整數(x)轉換爲單個字符的x值

例如,對於數據:銷售(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) 

- --not肯定代碼在這裏---

 Console.WriteLine(year & ": " & ????????) 
    Next 

    Console.ReadLine() 
End Sub 

End Module 

我如何整數值從ARR內改變只是不確定a成一定數量的單個字符。

回答

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

爲什麼不只是新的字符串(「+」c,i)? – 2012-04-02 14:30:08

+0

因爲我總是忘記構造函數超載;) – 2012-04-02 14:38:43

1

不會添加一個顯示多次「 - 」就足夠了嗎?

就像是:

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 
+0

這仍然爲我提供了1個額外,說我進入了銷售(3,2,3,4,3)的出放正顯示出4,3,4 ,5,4 – 2012-03-31 14:41:20

+0

是的,我的錯誤,我開始for..next在s = 0 我應該寫「對於s = 1銷售(索引)」而不是 – Mesop 2012-03-31 14:44:07

+0

現在明白:)謝謝你olch – 2012-03-31 15:02:39