Probability Board "toy"

Hey guys. i'm a newbie when it comes to c++ , i have an assignment
Problem description In this assignment, you are requested to write a program that implements the “probability board” toy, shown in the following diagram. The toy works as follows. You start by dropping a marble in the hole at the top. The marble falls down and hits the uppermost peg, indicated by the small circle in the diagram. The marble bounces off the peg and falls, with equal probability, to the left or right. Whichever way it goes, it then hits a peg on the second level and bounces again, one direction or the other. The process continues until the marble passes all nine-level of pegs and drops into one of the 10 channels at the bottom. For example, the colored line in the diagram shows one possible path for the marble:
Your program should simulate the operation of dropping 50 marbles into the toy. The probability to left or right can be simulated using random number generator. Your program should display its results pictorially using histogram. A sample of the output of this program is as follows: <<This program simulates the probability board toy>> Do you like to play (Y/N) ? Y 1 | ***** 2 | ***** 3 | ***** 4 | ***** 5 | ***** 6 | ***** 7 | ***** 8 | ***** 9 | ***** 10 | ***** Do you like to play (Y/N)? N Press any key to continue


i have no idea as to how to start writing this.. any help would be appreciated
Having spent a whole term or semester in class, you must have some idea where to start. We can help, but you must have some opinion on how you might start.
I think I have to use a random number generator.. but then not quite sure how to make it use * instead of numbers.. and by the way my classes are all in Chinese.. and I'm not an Asian
C++ inherits pretty much all the stuff in C, so I'll start with C as things are more basic there.

In C, there is a (pseudo) random number generator. All these PRNGs work by giving you the next number in a sequence. The start of the sequence is called the seed. The idea is you get a number back that's more or less unpredictable.

In C, you set the seed with srand(), and you get the next number in the sequence with rand(). The range of the number is the range of an int.

This C++ program uses the C PRNG to print the first 10 numbers from a given seed,
1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <stdlib.h>

int main()
{
    srand(2015);  // set the seed
    for (int i = 0; i != 10; ++i)
        std::cout << i << rand() << ' ';
    std::cout << '\n';
}


It is common to use srand(time(NULL)); to seed the PRNG with an unpredictable seed, so each time the program is run, it generates different numbers. Our program above will print the same numbers each time it is run.

If we want random numbers in the range of 0 - 5, so we can simulate throwing dice, we can use the mathematical modulus operation; rand() % 6.

If we want a number of values 0 or 1, so we can make a binary decision, we can use rand() % 2.

So, let's write a program that does exactly that; loops 10 times, printing a random left/right decision.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <time.h>
#include <stdlib.h>

int main()
{
    srand(time(nullptr));  // use an unpredictable seed

    for (int i = 0; i != 10; ++i)
        switch (rand() % 2)
        {
        case 0:
            std::cout << "left" << std::endl;
            break;
        case 1:
            std::cout << "right" << std::endl;
            break;
        default:
            std::clog << "unexpected value from rand()" << std::endl;
        }
}


Let us know if you don't understand any part of this.
it seems like i have to use a random number generator and generate these numbers inside of a 10 element sized array.. but how do i distribute those 50 values evenly and randomly at the same time.. that's where im stuck.. doesnt have to be even but all the * should add up to 50...
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include <iostream>
#define SIZE 10
using namespace std;





int main(void)



{
srand(time(0));


int channel[SIZE]={0,rand()%50 +1};
int row, col;

cout<< " do you like to play?";
cout<< endl;



for( row=0; row<=(SIZE-1); row++) { cout << " "<< row+1, channel[row];cout<< "| ";
for (col = 1; col<= channel[row]; ++col){cout << "*" ;
}

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

}
Topic archived. No new replies allowed.