fork download
  1. /*
  2. Program stores 2 random values between 1 and 4 in 2 different variables.
  3. It then compares those values to see if they are the same. The program
  4. runs 100 times and stores the average then displays the % probably that
  5. both values will be the same.
  6.  
  7. */
  8.  
  9.  
  10. #include<iostream>
  11. #include<time.h>
  12. #include <stdlib.h>
  13. using namespace std;
  14.  
  15. int main(){
  16. double total=0;
  17. srand(time(NULL));
  18. int num1;
  19. int num2;
  20. for(int i=0;i<100;i++){
  21. num1=rand() % 4 +1;
  22. num2=rand() % 4 +1;
  23. cout<<"Tire Guess 1: "<<num1<<" Tire Guess 2: "<<num2<<endl<<endl;
  24.  
  25. if(num1==num2){
  26. total++;
  27. }
  28. }
  29. total=total/100*100;
  30. cout<<"Probability of them guessing the same is: "<<total<<"%"<<endl;
  31.  
  32. system("pause");
  33.  
  34.  
  35. }
Success #stdin #stdout #stderr 0s 3296KB
stdin
Standard input is empty
stdout
Tire Guess 1: 2 Tire Guess 2: 2

Tire Guess 1: 1 Tire Guess 2: 3

Tire Guess 1: 1 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 3

Tire Guess 1: 1 Tire Guess 2: 2

Tire Guess 1: 4 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 2

Tire Guess 1: 4 Tire Guess 2: 3

Tire Guess 1: 4 Tire Guess 2: 3

Tire Guess 1: 1 Tire Guess 2: 3

Tire Guess 1: 2 Tire Guess 2: 4

Tire Guess 1: 3 Tire Guess 2: 4

Tire Guess 1: 2 Tire Guess 2: 3

Tire Guess 1: 4 Tire Guess 2: 3

Tire Guess 1: 2 Tire Guess 2: 4

Tire Guess 1: 4 Tire Guess 2: 3

Tire Guess 1: 2 Tire Guess 2: 4

Tire Guess 1: 1 Tire Guess 2: 2

Tire Guess 1: 4 Tire Guess 2: 4

Tire Guess 1: 4 Tire Guess 2: 1

Tire Guess 1: 1 Tire Guess 2: 3

Tire Guess 1: 1 Tire Guess 2: 3

Tire Guess 1: 1 Tire Guess 2: 4

Tire Guess 1: 2 Tire Guess 2: 4

Tire Guess 1: 2 Tire Guess 2: 2

Tire Guess 1: 2 Tire Guess 2: 3

Tire Guess 1: 1 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 2

Tire Guess 1: 3 Tire Guess 2: 2

Tire Guess 1: 1 Tire Guess 2: 4

Tire Guess 1: 2 Tire Guess 2: 4

Tire Guess 1: 3 Tire Guess 2: 3

Tire Guess 1: 4 Tire Guess 2: 3

Tire Guess 1: 4 Tire Guess 2: 3

Tire Guess 1: 2 Tire Guess 2: 3

Tire Guess 1: 3 Tire Guess 2: 2

Tire Guess 1: 1 Tire Guess 2: 4

Tire Guess 1: 1 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 2

Tire Guess 1: 4 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 2

Tire Guess 1: 3 Tire Guess 2: 3

Tire Guess 1: 2 Tire Guess 2: 1

Tire Guess 1: 1 Tire Guess 2: 4

Tire Guess 1: 3 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 4

Tire Guess 1: 4 Tire Guess 2: 1

Tire Guess 1: 2 Tire Guess 2: 3

Tire Guess 1: 4 Tire Guess 2: 1

Tire Guess 1: 2 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 4

Tire Guess 1: 3 Tire Guess 2: 3

Tire Guess 1: 3 Tire Guess 2: 3

Tire Guess 1: 4 Tire Guess 2: 2

Tire Guess 1: 4 Tire Guess 2: 3

Tire Guess 1: 2 Tire Guess 2: 2

Tire Guess 1: 4 Tire Guess 2: 4

Tire Guess 1: 4 Tire Guess 2: 1

Tire Guess 1: 1 Tire Guess 2: 4

Tire Guess 1: 4 Tire Guess 2: 3

Tire Guess 1: 4 Tire Guess 2: 3

Tire Guess 1: 2 Tire Guess 2: 4

Tire Guess 1: 3 Tire Guess 2: 3

Tire Guess 1: 2 Tire Guess 2: 2

Tire Guess 1: 3 Tire Guess 2: 3

Tire Guess 1: 3 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 2

Tire Guess 1: 2 Tire Guess 2: 2

Tire Guess 1: 1 Tire Guess 2: 3

Tire Guess 1: 3 Tire Guess 2: 4

Tire Guess 1: 3 Tire Guess 2: 2

Tire Guess 1: 1 Tire Guess 2: 3

Tire Guess 1: 2 Tire Guess 2: 4

Tire Guess 1: 1 Tire Guess 2: 1

Tire Guess 1: 2 Tire Guess 2: 2

Tire Guess 1: 4 Tire Guess 2: 1

Tire Guess 1: 4 Tire Guess 2: 2

Tire Guess 1: 2 Tire Guess 2: 2

Tire Guess 1: 4 Tire Guess 2: 4

Tire Guess 1: 2 Tire Guess 2: 2

Tire Guess 1: 4 Tire Guess 2: 4

Tire Guess 1: 3 Tire Guess 2: 2

Tire Guess 1: 2 Tire Guess 2: 4

Tire Guess 1: 3 Tire Guess 2: 2

Tire Guess 1: 3 Tire Guess 2: 1

Tire Guess 1: 1 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 1

Tire Guess 1: 3 Tire Guess 2: 4

Tire Guess 1: 1 Tire Guess 2: 3

Tire Guess 1: 4 Tire Guess 2: 2

Tire Guess 1: 4 Tire Guess 2: 4

Tire Guess 1: 2 Tire Guess 2: 3

Tire Guess 1: 1 Tire Guess 2: 4

Tire Guess 1: 4 Tire Guess 2: 4

Tire Guess 1: 3 Tire Guess 2: 1

Tire Guess 1: 2 Tire Guess 2: 3

Tire Guess 1: 4 Tire Guess 2: 4

Tire Guess 1: 4 Tire Guess 2: 1

Probability of them guessing the same is: 27%
stderr
sh: pause: not found