#include<stdlib.h>
#include<qmessagebox.h>
#include<time.h>
void MainWindow::ButtonHandler()
{
int math[20][20];
for (int row = 1; row < 20; row++) {
for (int col = 1; col < 20; col++) {
math[row][col]=0;}}
int aux2=0;
int aux3=0;
srand(time(NULL));
for(int i=0;i<100;i++)
{
bool set = false;
while(!set)
{
aux2=int( rand()%20);
aux3=int( rand()%20);
if(math[aux2][aux3]==0)
{
math[aux2][aux3] = 1;
set = true;
}
}
}
int demonstration=0;
for (int row = 1; row < 20; row++) {
for (int col = 1; col < 20; col++) {
if(math[row][col]==1)demonstration++;}}
msg
->setText
(QString::number(demonstration
));
msg->show();
}
#include<stdlib.h>
#include<qmessagebox.h>
#include<time.h>
void MainWindow::ButtonHandler()
{
int math[20][20];
for (int row = 1; row < 20; row++) {
for (int col = 1; col < 20; col++) {
math[row][col]=0;}}
int aux2=0;
int aux3=0;
srand(time(NULL));
for(int i=0;i<100;i++)
{
bool set = false;
while(!set)
{
aux2=int( rand()%20);
aux3=int( rand()%20);
if(math[aux2][aux3]==0)
{
math[aux2][aux3] = 1;
set = true;
}
}
}
int demonstration=0;
for (int row = 1; row < 20; row++) {
for (int col = 1; col < 20; col++) {
if(math[row][col]==1)demonstration++;}}
QMessageBox *msg=new QMessageBox;
msg->setText(QString::number(demonstration));
msg->show();
}
To copy to clipboard, switch view to plain text mode
and it dosn't all time give 100!!!(i'v made this program just to show you...)
Bookmarks