online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include <iostream> #include <vector> #include <string> struct Box { std::string Ball1; std::string Ball2; }; int main() { // ΠšΠΎΡ€ΠΎΠ±ΠΊΠΈ с ΡˆΠ°Ρ€Π°ΠΌΠΈ std::vector<Box> boxes; boxes.push_back({ "gold", "gold" }); boxes.push_back({ "gold", "silver" }); //boxes.push_back({ "silver", "silver" }); // ВянСм ΡˆΠ°Ρ€Ρ‹ const int N = 1000000; int winCount = 0; int chosen_index; std::string chosen_ball; std::string remaining_ball; for (int i = 0; i < N; i++) { rechoseBox: // Π’Ρ‹Π±ΠΎΡ€ случайной ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ Box box = boxes[std::rand() % boxes.size()]; if (box.Ball1 != "gold" && box.Ball2 != "gold") { // НС Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹ΠΉ случай ΠΏΠΎ ΡƒΡΠ»ΠΎΠ²ΠΈΡŽ (коллапс всСлСнной) => Π²Ρ‹Π±ΠΈΡ€Π°Π΅ΠΌ ΠΊΠΎΡ€ΠΎΠ±ΠΊΡƒ Π΅Ρ‰Ρ‘ Ρ€Π°Π· goto rechoseBox; } rechoseBall: // 1) ВянСм ΠΏΠ΅Ρ€Π²Ρ‹ΠΉ ΡˆΠ°Ρ€ ΠΈΠ· ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ, ΠΎΠ½ Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΎΠΊΠ°Π·Π°Ρ‚ΡŒΡΡ Π·ΠΎΠ»ΠΎΡ‚ΠΎΠΉ (Π΄Ρ€ΡƒΠ³ΠΈΠ΅ случаи ΠΏΠΎ ΡƒΡΠ»ΠΎΠ²ΠΈΡŽ Π½Π΅ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹) chosen_index = std::rand() % 2; if (chosen_index == 0) { chosen_ball = box.Ball1; remaining_ball = box.Ball2; } else { chosen_ball = box.Ball2; remaining_ball = box.Ball1; } if (chosen_ball == "silver") { // НС Π²ΠΎΠ·ΠΌΠΎΠΆΠ½Ρ‹ΠΉ случай ΠΏΠΎ ΡƒΡΠ»ΠΎΠ²ΠΈΡŽ (коллапс всСлСнной) => Π²Ρ‹Π±ΠΈΡ€Π°Π΅ΠΌ ΠΊΠΎΡ€ΠΎΠ±ΠΊΡƒ Π΅Ρ‰Ρ‘ Ρ€Π°Π· goto rechoseBall; } // 2) Π Π°Π½Π΄ΠΎΠΌΠ½ΠΎ тянСм Π²Ρ‚ΠΎΡ€ΠΎΠΉ ΡˆΠ°Ρ€ ΠΈΠ· Ρ‚ΠΎΠΉ ΠΆΠ΅ ΠΊΠΎΡ€ΠΎΠ±ΠΊΠΈ ΠΈ ΡƒΠ²Π΅Π»ΠΈΡ‡ΠΈΠ²Π°Π΅ΠΌ счётчик, Ссли ΠΎΠ½ оказался Π·ΠΎΠ»ΠΎΡ‚Ρ‹ΠΌ winCount += remaining_ball == "gold"; } std::cout << "Answer = " << (double)winCount / 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