Thanks for the explaination! For the last part of the assignment, there is something similar to what you've done for displaying the sum and number of times it has been rolled. The only difference is that it must be output into a bar graph.
"Once the rolls are completed the program will display a bar graph, like the one below, showing the sum value, the number of times it was rolled, and a bar of asterisks each one representing 2% of the highest count recorded in this run. In the example below, the highest value is 464, therefor, each asterisk is 2% of 464 which, rounded down, is 9. So, for the highest value of 464 there are 49 asterisks."
Given to us was the start of the bar graph which is,
1 2 3 4 5 6 7
|
cout << "For " << # of dice << " dice, rolled " << # of rolls << " times" << endl;
cout << "Count %:--- 0 10 20 30 40 50 60 70 80 90 100" << endl;
cout << "Sum count |....|....|....|....|....|....|....|....|....|....|" << endl;
cout << " " << setw(2) << sum of dice faces ; // Formatting so Sum and count columns
cout << " (" << setw(4) << # of times rolled << ") "; // are neat and tidy.
|
I've tried to work this code into what I already have, but I cannot get the correct amount of asterisks to display for each sum. What am I doing wrong? We haven't had any experience with making such graphs, so I'm completely lost.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
cout << "For " << dieNumber << " dice, rolled " << dieRoll << " times" << endl;
cout << "Count %:--- 0 10 20 30 40 50 60 70 80 90 100" << endl;
cout << "Sum count |....|....|....|....|....|....|....|....|....|....|" << endl;
for (int s = 0; s < MAXSUM; ++s) {
double v = 0.02;
double b;
double n;
b = v * dieSums[s];
n = dieSums[s] / b;
if (dieSums[s] != 0) {
cout << "\n";
cout << " " << setw(2) << s; // Formatting so Sum and count columns
cout << " (" << setw(4) << dieSums[s] << ") "; // are neat and tidy.
cout << " " << setw(n) << setfill('*');
}
}
|
Here is the output the program must match
https://imgur.com/a/0acDgg4