GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 17-Nov-2005, 22:24
kris5683 kris5683 is offline
New Member
 
Join Date: Oct 2005
Posts: 7
kris5683 is on a distinguished road

sudoku help


im trying to create a program that will open a file and read it, then check to see if it is a solution for a sudoku puzzle. so far i have....

CPP / C++ / C Code:
fstream infile;

infile.open ( "good.txt", ifstream::in );

if ( infile.is_open() == false ) {
  cout << "couldn't open " << endl;
}
int i;
int k;
int a [9] [9];
for (int i=0; i<9; i++)
{
  for (int k=0; k<9; k++)
  {
    if (a[i][k]==k+1) 
    {
     cout << "solved" << endl;
    }
    if(a[i][k]!=k+1)
    {
      cout<<"row "<<i<<" is missing "<<k+1<<endl;
    }
  }
}
return 0;

}

my problem is that it doesnt diplay what it should. its like it isnt opening the file or reading it.

am i missing something?


also...im not sure how to have it check for a solution in a 3x3 square...any suggestionS?
Last edited by LuciWiz : 18-Nov-2005 at 03:51. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 18-Nov-2005, 00:48
Guidelines Plz Guidelines Plz is offline
Junior Member
 
Join Date: Sep 2005
Posts: 87
Guidelines Plz is on a distinguished road

Re: sudoku help


Kris,
You have been asked to use code tags twice, and to read the Guidelines. Is there something in the Guidelines you didn't understand?

Quote:
Originally Posted by kris5683
im trying to create a program that will open a file and read it, then check to see if it is a solution for a sudoku puzzle. so far i have....
Guideline 6: you already have a thread on this sudoku topic.

Quote:
Originally Posted by kris5683
fstream infile;

infile.open ( "good.txt", ifstream::in );

if ( infile.is_open() == false ) {
cout << "couldn't open " << endl;
}
int i;
etc...
Guideline 1: Can't read the code without formatting -- CODE TAGS


Quote:
Originally Posted by kris5683
my problem is that it doesnt diplay what it should. its like it isnt opening the file or reading it.
Guideline 2: Explanation... What IS it displaying. What SHOULD it display? How have you tracked down where the error seems to be?

Quote:
Originally Posted by kris5683
am i missing something?
Yes. Doing what's requested so we can help to the best of our ability. Help is a two-way street. You supply understandable information, we supply help to increase your knowledge and finish your project.
__________________

Please read http://www.gidforums.com/t-5566.html. They were written to help you create a request that is readable and has enough information we can actually tell what you need help with.
  #3  
Old 18-Nov-2005, 06:58
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,309
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: sudoku help


Quote:
Originally Posted by kris5683
im trying to create a program that will open a file and read it, then check to see if it is a solution for a sudoku puzzle.
my problem is that it doesnt diplay what it should. its like it isnt opening the file or reading it.

am i missing something?


also...im not sure how to have it check for a solution in a 3x3 square...any suggestionS?


1. You aren't reading anything from the file. Forget the calculations for now. Open and read the file into an array. Then print out the values that are in the array so that you can be sure that data are what you think the program needs to be.

If there is something about this that you don't understand, show us exactly what is in your input file and show us what your program prints out.

After you are sure that you can read the file perfectly, then try the calculations.

2. Work out an example with pencil and paper. Show us the example (tell us what the data in "good.txt" is). Show us how you performed some of the calculations manually.

The, put debug statements (cout<<) at places in your program where calculations are performed. Show the results of calculations at each step of the program (make the program print out the calculations as it performs them).

Regards,

Dave
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
sudoku kris5683 C++ Forum 1 08-Nov-2005 08:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:20.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.