dimanche 30 octobre 2016

Convert my J.s code to C++

//Ignore the graphics.My goal is to print the most occurred number,which in this case is 7.

var count = 0;

var num = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

draw = function() {

if (count < 1000) {

    count ++;

    for (var i = 0; i < 100; i ++) {

        num[floor(random(6) + 1) + floor(random(6) + 1)] ++;

    }

    background(255);
    fill(0);
    for (var i = 2; i < num.length; i ++) {

        rect(25 + i*25, 400 - num[i]/42, 17, num[i]/42);

    }

    for (var i = 2; i < num.length; i ++) {

        text(i + ": " + num[i], 15, i*20 - 15);

    }

} else {

    background(255);
    fill(0);
    for (var i = 2; i < num.length; i ++) {

        rect(25 + i*25, 400 - num[i]/42, 17, num[i]/42);

    }

    for (var i = 2; i < num.length; i ++) {

        text(i + ": " + num[i], 15, i*20 - 15);

    }

}

};

Aucun commentaire:

Enregistrer un commentaire