online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <stdio.h> #include <stdlib.h> #include <time.h> int battle_wrong() { int chance = random() % 100; if (chance <= 2) return 7; if (chance <= 5) return 5; if (chance <= 8) return 3; if (chance <= 10) return 2; if (chance <= 25) return 1; return 0; } int battle_ok() { int chance = random() % 100; if (chance < 2) return 7; if (chance < (2+5)) return 5; if (chance < (2+5+8)) return 3; if (chance < (2+5+8+10)) return 2; if (chance < (2+5+8+10+25)) return 1; return 0; } int main() { time_t t; int i; int prices_ok = 0; int prices_wrong = 0; srand((unsigned) time(&t)); for (i = 0; i < 4000; i++) { prices_ok += battle_ok(); prices_wrong += battle_wrong(); } printf("%d battles\n", i); printf(" ok -> %d prices (%.2f prices/battle)\n", prices_ok, float(prices_ok)/i); printf(" wrong -> %d prices (%.2f prices/battle)\n", prices_wrong, float(prices_wrong)/i); return 0; }

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