hi guys i want to generate a number of matrices of 5x5 with random numbers but this code i made only prints the same matrix over and over, whats the issue? (i am learning c++), this code just print the same matrix over and over instead of being different numbers in each matrix
#include <iostream>
#include <string>
#include <sstream>
#include <ctime>
#include <iomanip>
#include <cstdlib>
using namespace std;
bool verif(int carton[5][5], int f, int c, int nume){
for(f=0;f<5;f++){
for(c=0;c<5;c++){
if(nume==carton[f][c]){
return false;
}
}
}
return true;
}
int i,cant,nume;
int main()
{
ingresa:
int j,cant;
cout<< "type the number of bingo cards you want: ";
cin>>cant;
if(cant>100){
cout<<"ERROR the max number of bingo cards is 100:"<<endl;
goto ingresa;
}
for(i=1;i<=cant;i++){
cout<<endl;
cout<< "BINGO #"<<i<<endl;
int carton[5][5]; //cartón de 5x5
int f,c,nume;
srand(time(NULL));
for(f=0;f<5;f++){
for(c=0;c<5;c++){
nume=1+rand()%25;
carton[f][c]=nume;
while(verif(carton,5,5,nume)==false){
nume=1+rand()%25;
}
carton[f][c]=nume;
}
}
for(f=0;f<5;f++){
for(c=0;c<5;c++){
cout<<setw(3)<<carton[f][c]<<" ";
}
cout<<endl;
}
}
}
Aucun commentaire:
Enregistrer un commentaire