Hi, I was thinking I should use "( int argc, char *argv[] )" model as in http://faq.cprogramming.com/cgi-bin/...&id=1043284376
I've read "int main ( void )" model is used when you do not require access to the command line arguments bearing in mind that, later, I want to remove some valors that should be entered by an user so I want to make a game. I am right with "( int argc, char *argv[] )" model? Anyway I've tried to use the other one too and I haven't got errors but in that code original printf sentences between while-if-break senetences don't appear when I run the program and the last one appers like no initialized so I don't solve the problem yet. (I've get that warning: warning C4508: 'main' : function should return a value; 'void' return type assumed). Here there is this last code (I've just typed int main() instead of void main()).
Code:
//sudoku.cpp:
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
#include<time.h>
int main(){
srand(time(0));
int a1;
int b1;
int c1;
int d1;
int a2;
int b2;
int c2;
int d2;
int a3;
int b3;
int c3;
int d3;
int a4;
int b4;
int c4;
int d4;
srand(time(0));
d4=0;
while(d4=0){
// 1st row
a1=(rand()%4)+1;
printf("a1 = %d\n",a1);
while((b1!=0)||(b1=a1)){
b1=rand()*5/32768;
if ((b1!=0)&&(b1!=a1)){
break;
printf("b1 %d\n",b1);
}}
printf("b1 = %d\n",b1);
while((c1!=0)||(c1=a1)||(c1=b1)){
c1=rand()*5/32768;
if ((c1!=0)&&(c1!=a1)&&(c1!=b1)){
break;
}}
printf("c1 = %d\n",c1);
while((d1!=0)||(d1=a1)||(d1=b1)||(d1=c1)){
d1=rand()*5/32768;
if ((d1!=0)&&(d1!=a1)&&(d1!=b1)&&(d1!=c1)){
break;
}}
printf("d1 = %d\n",d1);
// Column A
while((a2!=0)||(a2=a1)||(a2=b1)){
a2=rand()*5/32768;
if ((a2!=0)&&(a2!=a1)&&(a2!=b1)){
break;
}}
printf("a2 = %d\n",a2);
while((a3!=0)||(a3=a1)||(a3=a2)){
a3=rand()*5/32768;
if ((a3!=0)&&(a3!=a1)&&(a3!=a2)){
break;
}}
printf("a3 = %d\n",a3);
while((a4!=0)||(a4=a1)||(a4=a2)||(a4=a3)){
a4=rand()*5/32768;
if ((a4!=0)&&(a4!=a1)&&(a4!=a2)&&(a4!=a3)){
break;
}}
printf("a4 = %d\n",a4);
// Column D
while((d2!=0)||(d2=c1)||(d2=d1)||(d2=a2)){
d2=rand()*5/32768;
if ((d2!=0)&&(d2!=c1)&&(d2!=d1)&&(d2!=a2)){
break;
}}
printf("d2 = %d\n",d2);
while((d3!=0)||(d3=d1)||(d3=d2)||(d3=a3)){
d3=rand()*5/32768;
if ((d3!=0)&&(d3!=d1)&&(d3!=d2)&&(d3!=a3)){
break;
}}
printf("d3 = %d\n",d3);
while((d4!=0)||(d4=d1)||(d4=d2)||(d4=d3)||(d4=a4)){
d4=rand()*5/32768;
if ((d4!=0)&&(d4!=d1)&&(d4!=d2)&&(d4!=d3)&&(d4!=a4)){
break;
}}
printf("d4 = %d\n",d4);
// 4th row
while((b4!=0)||(b4=a3)||(b4=a4)||(b4=b1)||(b4=d4)){
b4=rand()*5/32768;
if ((b4!=0)&&(b4!=a3)&&(b4!=a4)&&(b4!=b1)&&(b4!=d4)){
break;
}}
printf("b4 = %d\n",b4);
while((c4!=0)||(c4=d3)||(c4=d4)||(c4=c1)||(c4=a4)||(c4=b4)){
c4=rand()*5/32768;
if ((c4!=0)&&(c4!=d3)&&(c4!=d4)&&(c4!=c1)&&(c4!=a4)){
break;
}}
printf("c4 = %d\n",c4);
// Central square
while((b2!=0)||(b2=a1)||(b2=b1)||(b2=a2)||(b2=d2)||(b2=b4)){
b2=rand()*5/32768;
if ((b2!=0)&&(b2!=a1)&&(b2!=b1)&&(b2!=a2)&&(b2!=d2)&&(b2!=b4)){
break;
}}
printf("b2 = %d\n",b2);
while((c2!=0)||(c2=c1)||(c2=d1)||(c2=a2)||(c2=b2)||(c2=d2)||(c2=c4)){
c2=rand()*5/32768;
if ((c2!=0)&&(c2!=c1)&&(c2!=d1)&&(c2!=a2)&&(c2!=b2)&&(c2!=d2)&&(c2!=c4)){
break;
}}
printf("c2 = %d\n",c2);
while((b3!=0)||(b3=a3)||(b3=a4)||(b3=b4)||(b3=b1)||(b3=b2||(b3=d3))){
b3=rand()*5/32768;
if ((b3!=0)&&(b3!=a3)&&(b3!=a4)&&(b3!=b4)&&(b3!=b1)&&(b3!=b2)&&(b3!=d3)){
break;
}}
printf("b3 = %d\n",b3);
while((c3!=0)||(c3=c4)||(c3=d4)||(c3=d3)||(c3=c1)||(c3=c2)||(c3=a3)||(c3=b3)){
c3=rand()*5/32768;
if ((c3!=0)&&(c3!=c4)&&(c3!=d4)&&(c3!=d3)&&(c3!=c1)&&(c3!=c2)&&(c3!=a3)&&(c3!=b3)){
break;
}}
printf("c3 = %d\n",c3);
if (b4!=0){
break;
}}
printf("a1 = %d\n",a1);
}
I've tried the "( int argc, char *argv[] )" model too, I dunno if I'm in the right way anyway I've post here it:
Code:
//sudoku.cpp:
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
#include<time.h>
int main(int a1, int b1, int c1, int d1, int a2, int b2, int c2, int d2, int a3, int b3, int c3, int d3, int a4, int b4, int c4, int d4){
srand(time(0));
int a1;
int b1;
int c1;
int d1;
int a2;
int b2;
int c2;
int d2;
int a3;
int b3;
int c3;
int d3;
int a4;
int b4;
int c4;
int d4;
srand(time(0));
d4=0;
while(d4=0){
// 1st row
a1=(rand()%4)+1;
printf("a1 = %d\n",a1);
while((b1!=0)||(b1=a1)){
b1=rand()*5/32768;
if ((b1!=0)&&(b1!=a1)){
break;
printf("b1 %d\n",b1);
}}
printf("b1 = %d\n",b1);
while((c1!=0)||(c1=a1)||(c1=b1)){
c1=rand()*5/32768;
if ((c1!=0)&&(c1!=a1)&&(c1!=b1)){
break;
}}
printf("c1 = %d\n",c1);
while((d1!=0)||(d1=a1)||(d1=b1)||(d1=c1)){
d1=rand()*5/32768;
if ((d1!=0)&&(d1!=a1)&&(d1!=b1)&&(d1!=c1)){
break;
}}
printf("d1 = %d\n",d1);
// Column A
while((a2!=0)||(a2=a1)||(a2=b1)){
a2=rand()*5/32768;
if ((a2!=0)&&(a2!=a1)&&(a2!=b1)){
break;
}}
printf("a2 = %d\n",a2);
while((a3!=0)||(a3=a1)||(a3=a2)){
a3=rand()*5/32768;
if ((a3!=0)&&(a3!=a1)&&(a3!=a2)){
break;
}}
printf("a3 = %d\n",a3);
while((a4!=0)||(a4=a1)||(a4=a2)||(a4=a3)){
a4=rand()*5/32768;
if ((a4!=0)&&(a4!=a1)&&(a4!=a2)&&(a4!=a3)){
break;
}}
printf("a4 = %d\n",a4);
// Column D
while((d2!=0)||(d2=c1)||(d2=d1)||(d2=a2)){
d2=rand()*5/32768;
if ((d2!=0)&&(d2!=c1)&&(d2!=d1)&&(d2!=a2)){
break;
}}
printf("d2 = %d\n",d2);
while((d3!=0)||(d3=d1)||(d3=d2)||(d3=a3)){
d3=rand()*5/32768;
if ((d3!=0)&&(d3!=d1)&&(d3!=d2)&&(d3!=a3)){
break;
}}
printf("d3 = %d\n",d3);
while((d4!=0)||(d4=d1)||(d4=d2)||(d4=d3)||(d4=a4)){
d4=rand()*5/32768;
if ((d4!=0)&&(d4!=d1)&&(d4!=d2)&&(d4!=d3)&&(d4!=a4)){
break;
}}
printf("d4 = %d\n",d4);
// 4th row
while((b4!=0)||(b4=a3)||(b4=a4)||(b4=b1)||(b4=d4)){
b4=rand()*5/32768;
if ((b4!=0)&&(b4!=a3)&&(b4!=a4)&&(b4!=b1)&&(b4!=d4)){
break;
}}
printf("b4 = %d\n",b4);
while((c4!=0)||(c4=d3)||(c4=d4)||(c4=c1)||(c4=a4)||(c4=b4)){
c4=rand()*5/32768;
if ((c4!=0)&&(c4!=d3)&&(c4!=d4)&&(c4!=c1)&&(c4!=a4)){
break;
}}
printf("c4 = %d\n",c4);
// Central square
while((b2!=0)||(b2=a1)||(b2=b1)||(b2=a2)||(b2=d2)||(b2=b4)){
b2=rand()*5/32768;
if ((b2!=0)&&(b2!=a1)&&(b2!=b1)&&(b2!=a2)&&(b2!=d2)&&(b2!=b4)){
break;
}}
printf("b2 = %d\n",b2);
while((c2!=0)||(c2=c1)||(c2=d1)||(c2=a2)||(c2=b2)||(c2=d2)||(c2=c4)){
c2=rand()*5/32768;
if ((c2!=0)&&(c2!=c1)&&(c2!=d1)&&(c2!=a2)&&(c2!=b2)&&(c2!=d2)&&(c2!=c4)){
break;
}}
printf("c2 = %d\n",c2);
while((b3!=0)||(b3=a3)||(b3=a4)||(b3=b4)||(b3=b1)||(b3=b2||(b3=d3))){
b3=rand()*5/32768;
if ((b3!=0)&&(b3!=a3)&&(b3!=a4)&&(b3!=b4)&&(b3!=b1)&&(b3!=b2)&&(b3!=d3)){
break;
}}
printf("b3 = %d\n",b3);
while((c3!=0)||(c3=c4)||(c3=d4)||(c3=d3)||(c3=c1)||(c3=c2)||(c3=a3)||(c3=b3)){
c3=rand()*5/32768;
if ((c3!=0)&&(c3!=c4)&&(c3!=d4)&&(c3!=d3)&&(c3!=c1)&&(c3!=c2)&&(c3!=a3)&&(c3!=b3)){
break;
}}
printf("c3 = %d\n",c3);
if (b4!=0){
break;
}}
printf("a1 = %d\n",a1);
}
With this code I get these errors:
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(13) : error C2082: redefinition of formal parameter 'a1'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(14) : error C2082: redefinition of formal parameter 'b1'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(15) : error C2082: redefinition of formal parameter 'c1'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(16) : error C2082: redefinition of formal parameter 'd1'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(17) : error C2082: redefinition of formal parameter 'a2'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(18) : error C2082: redefinition of formal parameter 'b2'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(19) : error C2082: redefinition of formal parameter 'c2'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(20) : error C2082: redefinition of formal parameter 'd2'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(21) : error C2082: redefinition of formal parameter 'a3'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(22) : error C2082: redefinition of formal parameter 'b3'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(23) : error C2082: redefinition of formal parameter 'c3'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(24) : error C2082: redefinition of formal parameter 'd3'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(25) : error C2082: redefinition of formal parameter 'a4'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(26) : error C2082: redefinition of formal parameter 'b4'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(27) : error C2082: redefinition of formal parameter 'c4'
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(28) : error C2082: redefinition of formal parameter 'd4'
And this warning:
C:\Documents and Settings\-\Mis documentos\Institut\TDR\TDR (Programació en C)\SUDOKU\Sudoku\4\4.cpp(179) : warning C4508: 'main' : function should return a value; 'void' return type assumed
If it's the correct way, how to solve these errors? If it's not how to make it work correctly (showing variables initialized)?
Thank you