这是一个计算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:*
然而,我的输入只是放了很多这样的星号 http://tinypic.com/view.php?pic=9h0wh2&s=8#.VHJjb4vF-QM 我不知道我做错了什么。
答案 0 :(得分:1)
基本上这里的问题只是一个错字/错误名称。
cout << "Please enter today's sales for store 1: " ;
cin >> store1;
您输入store1
,但在执行计算时您不会使用它,因为您有:
sale1 = sale1 / 100;
^^^^^
oops?
你真的应该编译你的代码并启用所有警告并注意它们。在这种情况下,您很可能已收到有关使用未初始化的变量的警告。养成这样做的习惯,因为它将来会对你有很大的帮助。