2014-11-23 83 views
-3

這是一個計算5個商店銷售額的計劃, ,我應該創建一個程序來顯示它今天的每個收入。 這是我到目前爲止有:銷售條形圖

#include <iostream> 
using namespace std; 

int main() 
{ 
//stores 1-5 variables 
int store1; int store2; int store3; int store4; int store5; 
// calculations 
int sale1; int sale2; int sale3; int sale4; int sale5; 

int counter; 



cout << "Please enter today's sales for store 1: " ; 
cin >> store1; 
cout << "Please enter today's sales for store 2: " ; 
cin >> store2; 
cout << "Please enter today's sales for store 3: " ; 
cin >> store3; 
cout << "Please enter today's sales for store 4: " ; 
cin >> store4; 
cout << "Please enter today's sales for store 5: " ; 
cin >> store5; 


cout << endl << "Sales Bar Chart"; 
cout << endl << "Each asterisks (*) respresents $100" << endl; 

sale1 = sale1/100; 
sale2 = sale2/100; 
sale3 = sale3/100; 
sale4 = sale4/100; 
sale5 = sale5/100; 

cout << "Store 1: "; 
    for (counter = 0; counter < sale1; counter++) 
      cout << '*'; 
    cout << endl << "Store 2: "; 
    for (counter = 0; counter < sale2; counter++) 
      cout << '*'; 
    cout << endl << "Store 3: "; 
    for (counter = 0; counter < sale3; counter++) 
      cout << '*'; 
    cout << endl << "Store 4: "; 
    for (counter = 0; counter < sale4; counter++) 
      cout << '*'; 
    cout << endl << "Store 5: "; 
    for (counter = 0; counter < sale5; counter++) 
      cout << '*'; 


    cin.get(); 
    cin.get(); 

我的問題是,程序是假設輸出銷售這樣

Enter today's sales for store 1 : 100 
Enter today's sales for store 2 : 200 
Enter today's sales for store 3 : 300 
Enter today's sales for store 4 : 400 
Enter today's sales for store 5 : 500 

銷售條形圖 每個*代表$ 100 存儲1:* 店2:* 店3:* 商店4:* 商店5:*

然而,我的投入只是把numerou這個星號的數量是這樣的 http://tinypic.com/view.php?pic=9h0wh2&s=8#.VHJjb4vF-QM 我不知道我做錯了什麼。

+2

*「我不知道我做了什麼」*不是一個很好研究的編程問題。 – 2014-11-23 22:50:10

+1

您是否正在閱讀編譯此代碼時得到的編譯器警告?你可能禁用了編譯器警告?您可以自動獲得類似您的拼寫錯誤的幫助。 – 2014-11-23 22:56:39

+0

好點。下次我會記住這一點,謝謝。 – 2014-11-23 23:08:35

回答

1

基本上這裏的問題只是一個錯字/錯誤的名字。

cout << "Please enter today's sales for store 1: " ; 
cin >> store1; 

您輸入store1但是當你做你的計算,因爲你有你不使用它:

sale1 = sale1/100; 
     ^^^^^ 
     oops? 

你真的應該編譯代碼啓用所有警告和注意他們。在這種情況下,您很可能會收到有關使用未初始化的變量的警告。養成這樣做的習慣,因爲它將在未來幫助你很多。

+0

謝謝!它的固定 – 2014-11-23 23:03:03

+0

@LocoDoco,很高興它有幫助。另外,如果答案在本網站上解決了您的問題,您可能希望通過單擊問題旁邊的複選標記來將答案標記爲已接受。這完全是可選的。 – shuttle87 2014-11-23 23:09:51

+0

謝謝!我非常感謝幫助。 – 2014-11-23 23:17:23