输出绑定到数组的符号 (C++)

Outputting a symbol tied to an array (C++)

本质上,我需要它为每辆售出的汽车显示一个星号,但是无论在第一个 for 循环中输入什么,它只吐出一次符号,我做错了什么?提前致谢。

#include <iostream>
#include <iomanip>
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销售的汽车

月销售额Sheet (每* = 1辆车)

员工 1:*

员工 2:*

员工 3:*

当月售出汽车总数:9

使用我上面给你的提示:

#include <iostream>
#include <string>
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: ****