本质上,我需要它为每一辆售出的汽车显示一个星号,然而,无论在第一个for循环中输入什么,它只输出一次符号,我做错了什么?提前谢谢。
#include
#include
using namespace std;
const int NUM_EMPLOYEES = 3;
int main()
{
int carsSold[NUM_EMPLOYEES];
int i;
int totalSales = 0;
char symbol = '*';
cout << "Welcome to the sales report program!\n";
cout << "\nThis program will produce a monthly sales report for the amount of cars sold.\n";
for (i = 0; i < NUM_EMPLOYEES; i++)
{
cout << "Enter the cars sold by employee " << i + 1 << ": ";
cin >> carsSold[i];
totalSales += carsSold[i];
}
cout << "\nMonthly Sales Sheet";
cout << "\n(each * = 1 car)\n";
for (i = 0; i < carsSold[i]; i++)
{
cout << "\nEmployee " << i + 1 << ": " << symbol << endl;
}
cout << "\nTotal cars sold for the month: " << totalSales;
return 0;
}下面是输出:
欢迎来到销售报告节目!
该程序将生成汽车销量的月度销售报告。
输入员工1: 3售出的汽车
输入员工2: 2售出的汽车
输入员工3: 4售出的汽车
每月销售表(每个*=1辆车)
员工1:*
员工2:*
员工3:*
当月汽车总销量:9辆
发布于 2021-02-25 13:44:03
使用我上面给你的提示:
#include
#include
using namespace std;
#define NUM_EMPLOYEES 3
...
cout << "\nMonthly Sales Sheet";
cout << "\n(each * = 1 car)\n";
for (i = 0; i < NUM_EMPLOYEES; i++)
{
auto bar = new string(carsSold[i], symbol);
cout << "\nEmployee " << i + 1 << ": " << *bar << endl;
}
cout << "\nTotal cars sold for the month: " << totalSales << "\n";
...这将导致以下输出:
This program will produce a monthly sales report for the amount of cars sold.
Enter the cars sold by employee 1: 3
Enter the cars sold by employee 2: 2
Enter the cars sold by employee 3: 4
Monthly Sales Sheet
(each * = 1 car)
Employee 1: ***
Employee 2: **
Employee 3: ****https://stackoverflow.com/questions/66362860
复制相似问题