Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,605 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 914 people online right now. Registration is fast and FREE... Join Now!




Stuck On Line In Soduku code

 
Reply to this topicStart new topic

Stuck On Line In Soduku code

michael1201
post 15 Jul, 2008 - 06:09 PM
Post #1


New D.I.C Head

*
Joined: 2 Jul, 2008
Posts: 13

I wrote a code and got stuck on this line it shows no errors but the code doesnt work as its suppose can someone tell me wats wrong here?

CODE
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
using namespace std;

void readAPuzzle(int grid[] [9]);
void printGrid(int grid[] [9]);
void ValidPuzzle(int grid[] [9]);

int main()
{
    int grid[9][9];

    readAPuzzle(grid);
    printGrid(grid);
    ValidPuzzle(grid);
    system("pause");
    return 0;
}


void readAPuzzle(int grid[] [9])
{
    ifstream in_f;    
    in_f.open("soduku.txt");
    
    for (int r = 0; r < 9; r++)
    for (int c = 0; c < 9; c++)
    in_f >> grid[r] [c];
}



//Prints out the puzzle read from file (keep)
void printGrid(int grid[] [9])
{

cout<<"Your Puzzle Is Listed Below: "<<endl;
for (int r = 0; r < 9; r++)
{

    if ((r)%3 == 0)
    cout<<endl<<endl;
    for (int c = 0; c < 9; c++)
{

    cout << (grid[r] [c]) << " ";
    if ((c+1)%3 == 0)
    cout<<"   ";
    }
    cout<<endl;
    }
    cout<<endl;
}


//Check Validity Of Puzzle
void ValidPuzzle(int grid[] [9])
{
    int sum = 0;
    int nototest = 0;
    int count = 0;
    int box[9][9], no_to_test;
    

/* check rows */


for(int r=0;r<9;r++)
{
for(int c=0;c<9;c++)
{
no_to_test = c+1;
count=0;

for(int d=0;d<9;d++)
{
if(box[r][d]==no_to_test)
{
count++;
}
}
if(count>1)
{
cout << "Sudoku Violation: The digit " << no_to_test
<< " appears more than once on row no. " << r+1
<< endl << "Any digit (1-9) can appear only once in each row of the box. Try Again!";

}
}
}}
User is offlineProfile CardPM

Go to the top of the page

lanec42
post 15 Jul, 2008 - 06:41 PM
Post #2


D.I.C Head

**
Joined: 25 Mar, 2008
Posts: 136


My Contributions


What exactly is your problem?
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 15 Jul, 2008 - 07:03 PM
Post #3


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,351



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


QUOTE(michael1201 @ 15 Jul, 2008 - 10:09 PM) *

I wrote a code and got stuck on this line

Which line?

QUOTE(michael1201 @ 15 Jul, 2008 - 10:09 PM) *

it shows no errors but the code doesnt work as its suppose


1.) What should it do?
2.) What is it doing instead?
User is online!Profile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 02:24AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month