Hey it's me again.
I'm still working on the magic square program, and the program is not working how I think it should be working. (I know I'm in error though )
Code:
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <stdbool.h>
#include "random.h"
int main()
{
bool test;
int x, y, z, w, p, l, randomer;
test= false;
int square[3][3];
for(x=0;x<3;x++)
for(y=0;y<3;y++)
square[x][y]=0;
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
for(z=1;z<10;z++)
{
while(test==false)
{
w=random();
switch(w)
{
case 1: if(square[0][0]!=0){ square[0][0]=w; test=true;} break;
case 2: if(square[1][0]!=0){ square[1][0]=w; test=true;} break;
case 3: if(square[2][0]!=0){ square[2][0]=w; test=true;} break;
case 4: if(square[0][1]!=0){ square[0][1]=w; test=true;} break;
case 5: if(square[1][1]!=0){ square[1][1]=w; test=true;} break;
case 6: if(square[2][1]!=0){ square[2][1]=w; test=true;} break;
case 7: if(square[0][2]!=0){ square[0][2]=w; test=true;} break;
case 8: if(square[1][2]!=0){ square[1][2]=w; test=true;} break;
case 9: if(square[2][2]!=0){ square[2][2]=w; test=true;} break;
}
}
test=false;
}
for(l=0;l<3;l++)
{
for(p=0;p<3;p++)
printf("%d",square[l][p]);
printf("\n");
}
getchar();
}
I believe it is stuck in an infinite loop somewhere... Because no display ever comes up and "Enter" does not end it as getchar(); should do..
also
Code:
int random()
{
return (int)(rand()%9 + 1);
}
is the random header. Just my experiment with headers. I know that works right. Unless you must use srand() in the place you use rand()
Thanks,
Zarakava.