1) You don't store an infinite number of dice values - no need to. Just
emit the value for each throw on the fly. Then keep 6 counters - one for
each of the 6 faces of the dice.
2) Emit the 6 counters. Percentage is just # of occurences * 100 / total
throws.
3) If the values you put into an array are in range 1-6, of course the
values stay in that range. However, normally when counting number of
times you get a one, a two etc, you store that in an array with index 0 to
5, since all arrays in C and C++ starts with index zero.
/Per W
On Tue, 6 Jul 2004, PETER CAMPOS wrote:
> hi everyone, thanx for all of the help on the last program. im still pretty lost on what to do with it though. below i want to roll a die a number of times, user input, and output:
> the face which was rolled, the occurence for each face and the percentage for that face.
> i have a lot of questions:
>
> 1) how do i create an array to hold an infinite number of rolls? i.e. if the user wanted to roll the die 1 million or 1 billion times. so far i've made two arrays of 6.
> 2) how to output the occurences and based on that the percentage. do i use the array i created?
> 3) since i am using 1+r%6 to determine range, are the faces 1-6 in elements 1-6 or do they stay in 0-5?
>
> cpp is not my forte. im considering dropping my class. any suggestions based on the types of questions i've asked?
>
> thanx again..
> Peter/Panos
>
>
> #include <iostream>
> #include <ctime>
> #include <cstdlib>
> using namespace std;
> int main()
> {
>
> int rolls;
> cout << "how many times do you want to roll the die? "; //how many times to roll die
> cin >> rolls; //user input
> int faces[6] = {0}; //array for storage of faces of die.
> //used later to calculate percentage
> int face;
> srand(time(0)); //user wants new random #'s generated each time
> int face_per;
>
> int die[6] = {1,2,3,4,5,6};
> for(int i = 0; i < rolls; i++){
> face = rand();
> face = 1+ face%6;
> cout << "the die has rolled: " << face << endl;
> }
> return 0;
> }
>
>
>
> ______________ ______________ ______________ ______________
> ccny.cuny.edu
>
>
>
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by Black Hat Briefings & Training.
> Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
> digital self defense, top technical experts, no vendor pitches,
> unmatched networking opportunities. Visit www.blackhat.com
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|