/* Program stores 2 random values between 1 and 4 in 2 different variables. It then compares those values to see if they are the same. The program runs 100 times and stores the average then displays the % probably that both values will be the same. */ #include<iostream> #include<time.h> #include <stdlib.h> using namespace std; int main(){ double total=0; srand(time(NULL)); int num1; int num2; for(int i=0;i<100;i++){ num1=rand() % 4 +1; num2=rand() % 4 +1; cout<<"Tire Guess 1: "<<num1<<" Tire Guess 2: "<<num2<<endl<<endl; if(num1==num2){ total++; } } total=total/100*100; cout<<"Probability of them guessing the same is: "<<total<<"%"<<endl; system("pause"); }
Standard input is empty
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%
sh: pause: not found