I have a problem with rand() function I want to build a program that shows the number of each face of dice when you throw it 6000 times
I wrote this code
#include <iostream>
using namespace std;
#include <iomanip>
using std::setw;
#include <cstdlib>
#include <ctime>
int main()
{
int face ;
int frequency1 =0;
int frequency2 =0;
int frequency3 =0;
int frequency4 =0;
int frequency5 =0;
int frequency6 =0;
for(int counter =1;counter <=6000;counter++){
face = 1+rand()%6;
switch(face){
case 1:
++frequency1;
break;
case 2:
++frequency1;
break;
case 3:
++frequency1;
break;
case 4:
++frequency1;
break;
case 5:
++frequency1;
break;
case 6:
++frequency1;
break;
default:
cout<<"program should never get here!!! ";
break;
}}
cout<<"the number of face 1 is : "<<frequency1<<endl;
cout<<"the number of face 2 is : "<<frequency2<<endl;
cout<<"the number of face 3 is : "<<frequency3<<endl;
cout<<"the number of face 4 is : "<<frequency4<<endl;
cout<<"the number of face 5 is : " <<frequency5<<endl;
cout<<"the number of face 6 is : " <<frequency6<<endl;
return 0;
}
Every time that i run this code it shows the same thing
the number of face 1 is : 6000
the number of face 2 is : 0
the number of face 3 is : 0
the number of face 4 is : 0
the number of face 5 is : 0
the number of face 6 is : 0