C++ C++;骰子滚动与图形 #包括 #包括 #包括
我正试图得到这样的输出,但我的图表不是我想要的。有什么建议吗?我该怎么做?如何正确定位它C++ C++;骰子滚动与图形 #包括 #包括 #包括,c++,graph,dice,C++,Graph,Dice,我正试图得到这样的输出,但我的图表不是我想要的。有什么建议吗?我该怎么做?如何正确定位它 这是我的代码输出。所以我最终找到了答案。最后,我将图形放在代码的另一部分,并使其正常工作 #include <iostream> #include<iomanip> #include <array> #include<string> using namespace std; int main() { const int arraysize = 13
这是我的代码输出。所以我最终找到了答案。最后,我将图形放在代码的另一部分,并使其正常工作
#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 你没试过…嗯…重新排序输出吗?是的,但没有成功。它把整个输出都搞砸了。那是怎么搞砸的?
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;
}