online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include <vector> struct Box { int goldBalls; int silverBalls; }; int main() { // Исходные коробки std::vector<Box> initialBoxes; initialBoxes.push_back({ 2, 0 }); initialBoxes.push_back({ 1, 1 }); initialBoxes.push_back({ 0, 2 }); // Коробки после того как вынули 1 золотой шар std::vector<Box> boxes; for (Box box : initialBoxes) { if (box.goldBalls >= 1) { box.goldBalls--; boxes.push_back(box); std::cout << "Box: silver = " << box.goldBalls << ", gold = " << box.silverBalls << "\n"; } } // Рассчёт вероятности что в нашей коробке второй шар золотой const int N = 1000000; int chosenGoldBall = 0; for (int i = 0; i < N; i++) { // Выбор случайной коробки Box box = boxes[std::rand() % boxes.size()]; // Увеличиваем счётчик, если случайно выбранный шар оказался золотым chosenGoldBall += std::rand() % (box.goldBalls + box.silverBalls) < box.goldBalls; } std::cout << "Answer = " << (double)chosenGoldBall / N << "\n"; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue