#include<fstream.h>
#include<stdio.h>
#include<string.h>
char num;
int don;
class sudoku
{
public:
void putin();
int retchar();
void putout();
char name[30];
int a1,a2,a3,a4,a5,a6,a7,a8,a9,b1,b2,b3,b4,b5,b6,b7,b8,b9,c1,c2,c3,c4,c5,c6,c7,c8,c9,d1,d2,d3,d4,d5,d6,d7,d8,d9,e1,e2,e3,e4,e5,e6,e7,e8,e9,f1,f2,f3,f4,f5,f6,f7,f8,f9,g1,g2,g3,g4,g5,g6,g7,g8,g9,h1,h4,h2,h3,h5,h6,h7,h8,h9,i1,i2,i3,i4,i5,i6,i7,i8,i9;
};
void sudoku::putin()
{
cout<<"\nEnter the Character of Sudoku ";
cin>>num;
cout<<"\nEnter the Name of Sudoku ";
gets(name);

cout<<"\nEnter the Values of first row ";
cin>>a1>>a2>>a3>>a4>>a5>>a6>>a7>>a8>>a9;
cout<<"\nEnter the Values of Second Row ";
cin>>b1>>b2>>b3>>b4>>b5>>b6>>b7>>b8>>b9;
cout<<"\nEnter the Third Row ";
cin>>c1>>c2>>c3>>c4>>c5>>c6>>c7>>c8>>c9;
cout<<"\nEnter the Values of the fourth row ";
cin>>d1>>d2>>d3>>d4>>d5>>d6>>d7>>d8>>d9;
cout<<"\nEnter the Values of Fifth Row ";
cin>>e1>>e2>>e3>>e4>>e5>>e6>>e7>>e8>>e9;
cout<<"\nEnter the Values of Sixth Row ";
cin>>f1>>f2>>f3>>f4>>f5>>f6>>f7>>f8>>f9;
cout<<"\nEnter the Values of Seventh Row ";
cin>>g1>>g2>>g3>>g4>>g5>>g6>>g7>>g8>>g9;
cout<<"\nEnter the Eighth Row ";
cin>>h1>>h2>>h3>>h4>>h5>>h6>>h7>>h8>>h9;
cout<<"\nEnter the Ninth Row ";
cin>>i1>>i2>>i3>>i4>>i5>>i6>>i7>>i8>>i9;
}
void sudoku::putout()
{
cout<<"\nThe Character is ";
cout<<num;
cout<<"\nEnter the Name of Sudoku ";
puts(name);

cout<<"\nEnter the Values of first row ";
cout<<a1<<a2<<a3<<a4<<a5<<a6<<a7<<a8<<a9;
cout<<"\nEnter the Values of Second Row ";
cout<<b1<<b2<<b3<<b4<<b5<<b6<<b7<<b8<<b9;
cout<<"\nEnter the Third Row ";
cout<<c1<<c2<<c3<<c4<<c5<<c6<<c7<<c8<<c9;
cout<<"\nEnter the Values of the fourth row ";
cout<<d1<<d2<<d3<<d4<<d5<<d6<<d7<<d8<<d9;
cout<<"\nEnter the Values of Fifth Row ";
cout<<e1<<e2<<e3<<e4<<e5<<e6<<e7<<e8<<e9;
cout<<"\nEnter the Values of Sixth Row ";
cout<<f1<<f2<<f3<<f4<<f5<<f6<<f7<<f8<<f9;
cout<<"\nEnter the Values of Seventh Row ";
cout<<g1<<g2<<g3<<g4<<g5<<g6<<g7<<g8<<g9;
cout<<"\nEnter the Eighth Row ";
cout<<h1<<h2<<h3<<h4<<h5<<h6<<h7<<h8<<h9;
cout<<"\nEnter the Ninth Row ";
cout<<i1<<i2<<i3<<i4<<i5<<i6<<i7<<i8<<i9;
}
int sudoku::retchar()
{
don=num;
return don;
}
void main()
{
sudoku sudoku1[3];
fstream sudo;
sudo.open("sudok.txt",ios::in|ios::out|ios::binary);
cout<<"\n\aEnter the Puzzles ";
for(int i=1;i<=3;++i)
{sudoku1[i].putin();
sudo.write((char*)&sudoku1[i],sizeof(sudoku1[i]));
}
sudo.seekg(0);
for(i=1;i<=3;++i)
{
sudo.read((char*)&sudoku1[i],sizeof(sudoku1[i]));
sudoku1[i].putout();
}
sudo.seekg(0);
cout<<"\nEnter the Type of Sudoku you want to play ";
cout<<"\nDo you want to play Easy,Medium or Tough ";
cout<<"\nEnter you choice ";
char type[20];
gets(type);
int rn;
if(strcmp(type,"tough")==0)
rn=36;
else if(strcmp(type,"medium")==0)
rn=35;
else
rn=64;
cout<<"\nThe Sudoku is ";
while(sudo.eof())
{
i=1;
sudo.read((char*)&sudoku1[i],sizeof(sudoku1[i]));
if(sudoku1[i].retchar()==rn)
{
sudoku1[i].putout();
break;
}
i++;
}
sudo.close();
}

I don't know why this program is causing an error as nothing seems to be wrong in this program...I wanted to write a program which would accept Sudoku(though not in Proper Sudoku format) and would show whichever Sudoku we want depending on our choice of an easy(@) medium(#) or Tough($) Sudoku.

Edited 6 Years Ago by WaltP: Added CODE Tags

Neither do we since "an error" is a useless explanation of the problem and there is no formatting at all making the program hard to follow.

See:
this, this, and this

This article has been dead for over six months. Start a new discussion instead.