lundi 15 février 2016

C++ rand() function in for loop

 #include<iostream>
 #include<cstdlib>
 using namespace std;
 int main()
 {
 int k;
 for(int j=0;j<5;j++)
 {
 k=(j+(rand()%4));
 cout<<k<<endl;
 }
 return 0;
 }

So my goal here was to reduce pick option for function rand() with every other lap but i get this crazy numbers like 6,5... which shouldn't be there




Aucun commentaire:

Enregistrer un commentaire