C++ 骰子滚动和图形

C++ dice rolling and graph

#include <iostream>
#include<iomanip>
#include <array>
#include<string>
using namespace std;

int main()
{
    const int arraysize = 13;
    string n;
    int counter[13];
    double sum=0;
    // init counter
    for (int i = 0; i < 13; i++)
        counter[i] = 0;

    int die1;
    int die2;

    for (int roll1 = 0; roll1 <= 36000000; roll1++) {
        die1 = 1 + rand() % 6;
        die2 = 1 + rand() % 6;
        counter[die1 + die2]++;
    }

    cout << "Rolls" << setw(13) << "Frequency" <<  endl;

    for (int face = 2; face < arraysize; face++)
    {
        for (int s = (counter[face] * 100 / 36000000); s > 0; s--) {
            cout <<  '*'; //output for graph
        }
        sum = ((sum + counter[face]) / 36000000) * 100; 
        cout << setw(7) << face << setw(13) << counter[face] << setw(15) << fixed << setprecision(1) << sum << endl;    
    }

    system("Pause");
    return 0;
}

代码输出

我正在尝试获得这样的输出,但我的图表并没有按照我想要的方式显示。有什么建议我该怎么做?如何正确定位它。

这是我的代码输出。

所以我最终弄明白了。我最终将图表放在代码的不同部分并使其正常工作。

for (int face = 2; face < arraysize; face++)
{

    sum = ((sum + counter[face]) / 36000000) * 100;
    cout << setw(7) << face << setw(13) << counter[face] << setw(15) << fixed << setprecision(1) << sum;


    for (int s = (counter[face] * 100 / 36000000); s > 0; s--) {

        cout << '*';

    }
    cout << endl;
}
system("Pause");
return 0;
}

感谢建议!