Party Vibe

Register

Welcome To

Any C++ Programmers?

Forums Life Computers, Gadgets & Technology Any C++ Programmers?

  • This topic is empty.
Viewing 15 posts - 16 through 30 (of 32 total)
  • Author
    Posts
  • @General Lighting 383377 wrote:

    Yes, but not that well (I dabble in bits of it). I tend to “cheat” and use GUI’s or even MSACCESS query tab to save time if possible.

    That said one of my next projects is to upload all the clients and staff telephone numbers onto a larger mysql database (from the ops system) and link it into the telephone system (which can generate a SQL query to a remote database). its not a particularly code-intensive project though..

    nice, I wish I could. Really should teach myself some programming/database skills, not done anything since my A level computing years ago.

    good luck with ur new DB

    i fuckin love mysql

    it makes a better partner with PHP than adam does with eve.

    I do want to be at uni. I just don’t like my course, if I pass everything this year I get to go straight into second year for the other course I want to do.

    you might be able to do it in a week, but it would involve locking yourself in your room, reading up every “crash course in C++” you can find, trying out bits of code as you go along and perhaps obtaining some modafinil or similar substance or at least a fuckload of caffeine (even if its 2l bottles of IRN-BRU which should be in abundance :laugh_at:

    If you want to do some sort of computer-related course you are going to have to learn at least the basics of programming. there weren’t even many mice and graphics displays when I started!

    Google

    looks like there is some stuff in google if you click the link, perhaps you could adapt the code.

    email this dude and hope he reply’s fast (it’s also got an explination of what he did and why when making the code) …

    Sudoku Board Generation Algorithm. HELP! – Page 2 – Code Forums

    I have looked at every one of those things before. I have NO idea how to implement them into my program code.

    This is my main cpp.
    // Sudoku

    #include
    using namespace std;

    #include “lamothe.h”

    int i, j;

    int grid[9][9] =
    {{0, 5, 1, 7, 0, 0, 0, 6, 2},
    {9, 0, 0, 0, 0, 6, 0, 0, 8},
    {8, 3, 0, 0, 0, 2, 1, 0, 0},
    {7, 4, 9, 0, 0, 1, 8, 0, 0},
    {1, 0, 0, 0, 0, 0, 0, 0, 9},
    {0, 0, 2, 3, 0, 0, 6, 1, 4},
    {0, 0, 5, 8, 0, 0, 0, 4, 6},
    {2, 0, 0, 9, 0, 0, 0, 0, 7},
    {6, 7, 0, 0, 0, 3, 5, 9, 0}};

    int grid2[9][9] =
    {{0, 5, 1, 7, 0, 0, 0, 6, 2},
    {9, 0, 0, 0, 0, 6, 0, 0, 8},
    {8, 3, 0, 0, 0, 2, 1, 0, 0},
    {7, 4, 9, 0, 0, 1, 8, 0, 0},
    {1, 0, 0, 0, 0, 0, 0, 0, 9},
    {0, 0, 2, 3, 0, 0, 6, 1, 4},
    {0, 0, 5, 8, 0, 0, 0, 4, 6},
    {2, 0, 0, 9, 0, 0, 0, 0, 7},
    {6, 7, 0, 0, 0, 3, 5, 9, 0}};

    int map(int); // declaration of map function – takes array co ordinates and converts to screen co ordinates

    class Input {
    public:
    void usrinpt(int k); // takes user input of 1-9 and displays on screen
    };

    void main(){
    char key =’Q’;
    int x = 0;
    int y = 0;

    int game_running = 1;

    void draw_grid();
    draw_grid();
    Draw_String(map(x),map(y), “”);

    while (game_running == 1){

    if(_kbhit()) { // wait for you
    key = toupper(_getch());
    switch (key){ // movement input
    case ‘W’: if (y>0)
    y–;
    break;
    case ‘A’: if (x>0)
    x–;
    break;
    case ‘S’: if (y<8)
    y++;
    break;
    case 'D': if (x<8)
    x++;
    break;
    case 'E': game_running = 0;
    break;
    }

    Draw_String(map(x),map(y), "");
    Input value;
    value.usrinpt(key);
    }
    }

    }

    void draw_grid() {
    int i, j;
    void drawch(int, int, int);

    Init_Graphics();
    Set_Color(15,15); // white background

    //top row
    Set_Color(15, 0);
    drawch(0, 0, 218);
    for(i=1; i<24; i++)
    if(i==8 || i==16)
    drawch(i, 0, 194);
    else
    drawch(i, 0, 196);
    drawch(24, 0, 191);

    // upper middle row
    drawch(0, 8, 195);
    for(i=1; i<24; i++)
    if(i==8 || i==16)
    drawch(i, 8, 197);
    else
    drawch(i, 8, 196);
    drawch(24, 8, 180);

    // lower middle row
    drawch(0, 16, 195);
    for(i=1; i<24; i++)
    drawch(i, 16, 196);
    drawch(24, 16, 180);

    // left side
    for(i=1; i<24; i++)
    drawch(0, i, 179);

    // left middle vertical
    drawch(0, 8, 196);
    for(i=1; i<24; i++)
    if(i==8 || i==16)
    drawch(8, i, 197);
    else
    drawch(8, i, 179);
    drawch(8, 24, 193);

    // right middle vertical
    drawch(0, 16, 196);
    for(i=1; i<24; i++)
    if(i==8 || i==16)
    drawch(16, i, 197);
    else
    drawch(16, i, 179);
    drawch(16, 24, 193);

    // right side
    for(i=1; i<24; i++)
    drawch(24, i, 179);

    // bottom row
    drawch(0, 24, 192);
    for(i=1; i<24; i++)
    if(i==8 || i==16)
    drawch(24, i, 193);
    else
    drawch(i, 24, 196);
    drawch(24, 24, 217);

    drawch(0, 8, 195);
    drawch(0, 16, 195);
    drawch(24, 8, 180);
    drawch(24, 16, 180);

    int cell;
    for(i=0; i<9; i++)
    for(j=0; j 0)
    cout << cell;
    else
    cout << " ";
    }
    Draw_String(78, 24, "");
    }

    void drawch(int x, int y, int ch){
    char str[] = "?";
    str[0] = ch;
    Draw_String(x, y, str);
    }

    int map(int k){
    int m = k*2;
    if(k<3)
    return (m + 2);
    else if(k 48) && (k < 58) && grid2[j][i] == true)
    cout < 48) && (k < 58) && grid2[j][i] == true)
    cout << (k – 48);
    This will give an error because of the fact grid2 is not boolean but in fact int. So without that, the program works but anything can be overwritten(the values you input and the values already there). And my class that I'm using apparently doesn't seem to actually do anything, so I'm wondering how do I create a class that does something? Would I make it into the grid? ie
    Class Grid() {
    int grid etc etc;
    }

    then call that from main?

    After that we have to other files one is a cpp and the other is a header. Anyone ever heard of lamothe? He is who we were given in order to implement graphics. However, according to a friend of mine one line of the code doesn't work. I'll let you look.

    This is the lamothe.cpp, apparently, this is where the line of code doesnt work.
    [CODE]// Taken from Andre LaMothe's book (see header file)
    #include "lamothe.h" // Added HH 26-11-'08

    CONSOLE_SCREEN_BUFFER_INFO con_info; // holds screen info // Added: define the variable here
    HANDLE hconsole; // handle to console // Added: define the variable here

    // FUNCTIONS //////////////////////////////////////////////

    void Init_Graphics(void)
    {
    // this function initializes the console graphics engine

    COORD console_size = {40,12}; // size of console

    // open i/o channel to console screen
    hconsole=CreateFile(TEXT("CONOUT$"),
    GENERIC_WRITE | GENERIC_READ,
    FILE_SHARE_READ | FILE_SHARE_WRITE,
    0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);

    // make sure we are in 80×25
    SetConsoleScreenBufferSize(hconsole,console_size);

    // get details for console screen
    GetConsoleScreenBufferInfo(hconsole,&con_info);

    } // end Init_Graphics

    ///////////////////////////////////////////////////////////

    void Set_Color(int fcolor, int bcolor=0)
    {
    // this function sets the color of the console output
    SetConsoleTextAttribute(hconsole,(WORD)((bcolor << 4) | fcolor));

    } // Set_Color

    ///////////////////////////////////////////////////////////

    void Draw_String(int x,int y, char *string)
    {
    // this function draws a string at the given x,y

    COORD cursor_pos; // used to pass coords

    // set printing position
    cursor_pos.X = x;
    cursor_pos.Y = y;
    SetConsoleCursorPosition(hconsole,cursor_pos);

    // print the string in current color
    printf("%s",string);

    } // end Draw_String

    [/CODE]

    And now lamothe.h
    [CODE]// Original source –

    // Andre La Mothe's book, The Black Art of 3D Games Programming, PROG2_1.CPP

    // I have reduced this program to essentials and written a simple function,
    // screen_layout(), to show the use of colour and movement of the cursor.

    // main() is the last function in the listing (screen_layout() precedes it).
    // Substitute main() with anything you like. You can then use standard i/o
    // or move the cursor about and change colour just as you wish.

    // This isn't going to rival a graphics engine – for that the current
    // second year module uses OpenGL which is a collection of C functions! –
    // but the use of colour and static / over-printing rather than scrolling
    // displays will make even simple turn-play games much more attractive.

    // Inclusion guards added so this file will only be compiled once within its own compilation module (within the object file)
    #ifndef __LAMOTHE_H__ // Added HH 26-11-'08
    #define __LAMOTHE_H__ // Added HH 26-11-'08

    // cjm 4-10-'01

    // INCLUDES ///////////////////////////////////////////////

    #include
    #include
    #include

    // DEFINES ////////////////////////////////////////////////

    #define MAX_X 77 // maximum x position for player
    #define SCROLL_POS 24 // the point that scrolling occurs

    // PROTOTYPES /////////////////////////////////////////////

    void Init_Graphics(void);
    void Set_Color(int fcolor, int bcolor);
    void Draw_String(int x,int y, char *string);

    // GLOBALS ////////////////////////////////////////////////

    // Variables declared extern because as projects grow in size possible variable name conflicts,
    // may occur if this header file is included in multiple files.
    extern CONSOLE_SCREEN_BUFFER_INFO con_info; // holds screen info // Added: extern, declare variable here but define it in lamothe.cpp file
    extern HANDLE hconsole; // handle to console // Added: extern, declare variable here but define it in lamothe.cpp file

    #endif // __LAMOTHE_H__ // Added HH 26-11-’08
    [/CODE]

    Now I’m wondering if most of you would agree this code is horrible to work with, that is why I’m asking for help. If I pass this module, I can go straight into 2nd year of my design course, not programming, design.[CODE]// Sudoku

    #include
    using namespace std;

    #include “lamothe.h”

    int i, j;

    int grid[9][9] =
    {{0, 5, 1, 7, 0, 0, 0, 6, 2},
    {9, 0, 0, 0, 0, 6, 0, 0, 8},
    {8, 3, 0, 0, 0, 2, 1, 0, 0},
    {7, 4, 9, 0, 0, 1, 8, 0, 0},
    {1, 0, 0, 0, 0, 0, 0, 0, 9},
    {0, 0, 2, 3, 0, 0, 6, 1, 4},
    {0, 0, 5, 8, 0, 0, 0, 4, 6},
    {2, 0, 0, 9, 0, 0, 0, 0, 7},
    {6, 7, 0, 0, 0, 3, 5, 9, 0}};

    int grid2[9][9] =
    {{0, 5, 1, 7, 0, 0, 0, 6, 2},
    {9, 0, 0, 0, 0, 6, 0, 0, 8},
    {8, 3, 0, 0, 0, 2, 1, 0, 0},
    {7, 4, 9, 0, 0, 1, 8, 0, 0},
    {1, 0, 0, 0, 0, 0, 0, 0, 9},
    {0, 0, 2, 3, 0, 0, 6, 1, 4},
    {0, 0, 5, 8, 0, 0, 0, 4, 6},
    {2, 0, 0, 9, 0, 0, 0, 0, 7},
    {6, 7, 0, 0, 0, 3, 5, 9, 0}};

    int map(int); // declaration of map function – takes array co ordinates and converts to screen co ordinates

    class Input {
    public:
    void usrinpt(int k); // takes user input of 1-9 and displays on screen
    };

    void main(){
    char key =’Q’;
    int x = 0;
    int y = 0;

    int game_running = 1;

    void draw_grid();
    draw_grid();
    Draw_String(map(x),map(y), “”);

    while (game_running == 1){

    if(_kbhit()) { // wait for you
    key = toupper(_getch());
    switch (key){ // movement input
    case ‘W’: if (y>0)
    y–;
    break;
    case ‘A’: if (x>0)
    x–;
    break;
    case ‘S’: if (y<8)
    y++;
    break;
    case ‘D’: if (x<8)
    x++;
    break;
    case ‘E’: game_running = 0;
    break;
    }

    Draw_String(map(x),map(y), “”);
    Input value;
    value.usrinpt(key);
    }
    }

    }

    void draw_grid() {
    int i, j;
    void drawch(int, int, int);

    Init_Graphics();
    Set_Color(15,15); // white background

    //top row
    Set_Color(15, 0);
    drawch(0, 0, 218);
    for(i=1; i<24; i++)
    if(i==8 || i==16)
    drawch(i, 0, 194);
    else
    drawch(i, 0, 196);
    drawch(24, 0, 191);

    // upper middle row
    drawch(0, 8, 195);
    for(i=1; i<24; i++)
    if(i==8 || i==16)
    drawch(i, 8, 197);
    else
    drawch(i, 8, 196);
    drawch(24, 8, 180);

    // lower middle row
    drawch(0, 16, 195);
    for(i=1; i<24; i++)
    drawch(i, 16, 196);
    drawch(24, 16, 180);

    // left side
    for(i=1; i<24; i++)
    drawch(0, i, 179);

    // left middle vertical
    drawch(0, 8, 196);
    for(i=1; i<24; i++)
    if(i==8 || i==16)
    drawch(8, i, 197);
    else
    drawch(8, i, 179);
    drawch(8, 24, 193);

    // right middle vertical
    drawch(0, 16, 196);
    for(i=1; i<24; i++)
    if(i==8 || i==16)
    drawch(16, i, 197);
    else
    drawch(16, i, 179);
    drawch(16, 24, 193);

    // right side
    for(i=1; i<24; i++)
    drawch(24, i, 179);

    // bottom row
    drawch(0, 24, 192);
    for(i=1; i<24; i++)
    if(i==8 || i==16)
    drawch(24, i, 193);
    else
    drawch(i, 24, 196);
    drawch(24, 24, 217);

    drawch(0, 8, 195);
    drawch(0, 16, 195);
    drawch(24, 8, 180);
    drawch(24, 16, 180);

    int cell;
    for(i=0; i<9; i++)
    for(j=0; j<9; j++){

    Draw_String(map(i), map(j), “”);
    cell = grid[j];
    if(cell > 0)
    cout << cell;
    else
    cout << " ";
    }
    Draw_String(78, 24, “”);
    }

    void drawch(int x, int y, int ch){
    char str[] = “?”;
    str[0] = ch;
    Draw_String(x, y, str);
    }

    int map(int k){
    int m = k*2;
    if(k<3)
    return (m + 2);
    else if(k<6)
    return (m + 4);
    else {
    return (m + 6);
    }
    }

    void Input::usrinpt(int k)
    {
    if ((k > 48) && (k < 58) && grid2[j]
    == true)
    cout << (k – 48);

    }
    [/CODE]

    void Input::usrinpt(int k)
    {
    if ((k > 48) && (k < 58) && grid2[j]
    == true)
    cout << (k – 48);
    This will give an error because of the fact grid2 is not boolean but in fact int. So without that, the program works but anything can be overwritten(the values you input and the values already there). And my class that I’m using apparently doesn’t seem to actually do anything, so I’m wondering how do I create a class that does something? Would I make it into the grid? ie
    Class Grid() {
    int grid etc etc;
    }

    then call that from main?

    After that we have to other files one is a cpp and the other is a header. Anyone ever heard of lamothe? He is who we were given in order to implement graphics. However, according to a friend of mine one line of the code doesn’t work. I’ll let you look.

    This is the lamothe.cpp, apparently, this is where the line of code doesnt work.
    // Taken from Andre LaMothe’s book (see header file)
    #include “lamothe.h” // Added HH 26-11-’08

    CONSOLE_SCREEN_BUFFER_INFO con_info; // holds screen info // Added: define the variable here
    HANDLE hconsole; // handle to console // Added: define the variable here

    // FUNCTIONS //////////////////////////////////////////////

    void Init_Graphics(void)
    {
    // this function initializes the console graphics engine

    COORD console_size = {40,12}; // size of console

    // open i/o channel to console screen
    hconsole=CreateFile(TEXT(“CONOUT$”),
    GENERIC_WRITE | GENERIC_READ,
    FILE_SHARE_READ | FILE_SHARE_WRITE,
    0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);

    // make sure we are in 80×25
    SetConsoleScreenBufferSize(hconsole,console_size);

    // get details for console screen
    GetConsoleScreenBufferInfo(hconsole,&con_info);

    } // end Init_Graphics

    ///////////////////////////////////////////////////////////

    void Set_Color(int fcolor, int bcolor=0)
    {
    // this function sets the color of the console output
    SetConsoleTextAttribute(hconsole,(WORD)((bcolor << 4) | fcolor));

    } // Set_Color

    ///////////////////////////////////////////////////////////

    void Draw_String(int x,int y, char *string)
    {
    // this function draws a string at the given x,y

    COORD cursor_pos; // used to pass coords

    // set printing position
    cursor_pos.X = x;
    cursor_pos.Y = y;
    SetConsoleCursorPosition(hconsole,cursor_pos);

    // print the string in current color
    printf("%s",string);

    } // end Draw_String

    [/CODE]

    And now lamothe.h
    [CODE]// Original source –

    // Andre La Mothe's book, The Black Art of 3D Games Programming, PROG2_1.CPP

    // I have reduced this program to essentials and written a simple function,
    // screen_layout(), to show the use of colour and movement of the cursor.

    // main() is the last function in the listing (screen_layout() precedes it).
    // Substitute main() with anything you like. You can then use standard i/o
    // or move the cursor about and change colour just as you wish.

    // This isn't going to rival a graphics engine – for that the current
    // second year module uses OpenGL which is a collection of C functions! –
    // but the use of colour and static / over-printing rather than scrolling
    // displays will make even simple turn-play games much more attractive.

    // Inclusion guards added so this file will only be compiled once within its own compilation module (within the object file)
    #ifndef __LAMOTHE_H__ // Added HH 26-11-'08
    #define __LAMOTHE_H__ // Added HH 26-11-'08

    // cjm 4-10-'01

    // INCLUDES ///////////////////////////////////////////////

    #include
    #include
    #include

    // DEFINES ////////////////////////////////////////////////

    #define MAX_X 77 // maximum x position for player
    #define SCROLL_POS 24 // the point that scrolling occurs

    // PROTOTYPES /////////////////////////////////////////////

    void Init_Graphics(void);
    void Set_Color(int fcolor, int bcolor);
    void Draw_String(int x,int y, char *string);

    // GLOBALS ////////////////////////////////////////////////

    // Variables declared extern because as projects grow in size possible variable name conflicts,
    // may occur if this header file is included in multiple files.
    extern CONSOLE_SCREEN_BUFFER_INFO con_info; // holds screen info // Added: extern, declare variable here but define it in lamothe.cpp file
    extern HANDLE hconsole; // handle to console // Added: extern, declare variable here but define it in lamothe.cpp file

    #endif // __LAMOTHE_H__ // Added HH 26-11-’08
    [/CODE]

    Now I’m wondering if most of you would agree this code is horrible to work with, that is why I’m asking for help. If I pass this module, I can go straight into 2nd year of my design course, not programming, design.[CODE]// Taken from Andre LaMothe’s book (see header file)
    #include “lamothe.h” // Added HH 26-11-’08

    CONSOLE_SCREEN_BUFFER_INFO con_info; // holds screen info // Added: define the variable here
    HANDLE hconsole; // handle to console // Added: define the variable here

    // FUNCTIONS //////////////////////////////////////////////

    void Init_Graphics(void)
    {
    // this function initializes the console graphics engine

    COORD console_size = {40,12}; // size of console

    // open i/o channel to console screen
    hconsole=CreateFile(TEXT(“CONOUT$”),
    GENERIC_WRITE | GENERIC_READ,
    FILE_SHARE_READ | FILE_SHARE_WRITE,
    0L, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0L);

    // make sure we are in 80×25
    SetConsoleScreenBufferSize(hconsole,console_size);

    // get details for console screen
    GetConsoleScreenBufferInfo(hconsole,&con_info);

    } // end Init_Graphics

    ///////////////////////////////////////////////////////////

    void Set_Color(int fcolor, int bcolor=0)
    {
    // this function sets the color of the console output
    SetConsoleTextAttribute(hconsole,(WORD)((bcolor << 4) | fcolor));

    } // Set_Color

    ///////////////////////////////////////////////////////////

    void Draw_String(int x,int y, char *string)
    {
    // this function draws a string at the given x,y

    COORD cursor_pos; // used to pass coords

    // set printing position
    cursor_pos.X = x;
    cursor_pos.Y = y;
    SetConsoleCursorPosition(hconsole,cursor_pos);

    // print the string in current color
    printf(“%s”,string);

    } // end Draw_String

    [/CODE]

    And now lamothe.h
    // Original source –

    // Andre La Mothe’s book, The Black Art of 3D Games Programming, PROG2_1.CPP

    // I have reduced this program to essentials and written a simple function,
    // screen_layout(), to show the use of colour and movement of the cursor.

    // main() is the last function in the listing (screen_layout() precedes it).
    // Substitute main() with anything you like. You can then use standard i/o
    // or move the cursor about and change colour just as you wish.

    // This isn’t going to rival a graphics engine – for that the current
    // second year module uses OpenGL which is a collection of C functions! –
    // but the use of colour and static / over-printing rather than scrolling
    // displays will make even simple turn-play games much more attractive.

    // Inclusion guards added so this file will only be compiled once within its own compilation module (within the object file)
    #ifndef __LAMOTHE_H__ // Added HH 26-11-’08
    #define __LAMOTHE_H__ // Added HH 26-11-’08

    // cjm 4-10-’01

    // INCLUDES ///////////////////////////////////////////////

    #include
    #include
    #include

    // DEFINES ////////////////////////////////////////////////

    #define MAX_X 77 // maximum x position for player
    #define SCROLL_POS 24 // the point that scrolling occurs

    // PROTOTYPES /////////////////////////////////////////////

    void Init_Graphics(void);
    void Set_Color(int fcolor, int bcolor);
    void Draw_String(int x,int y, char *string);

    // GLOBALS ////////////////////////////////////////////////

    // Variables declared extern because as projects grow in size possible variable name conflicts,
    // may occur if this header file is included in multiple files.
    extern CONSOLE_SCREEN_BUFFER_INFO con_info; // holds screen info // Added: extern, declare variable here but define it in lamothe.cpp file
    extern HANDLE hconsole; // handle to console // Added: extern, declare variable here but define it in lamothe.cpp file

    #endif // __LAMOTHE_H__ // Added HH 26-11-’08
    [/CODE]

    Now I’m wondering if most of you would agree this code is horrible to work with, that is why I’m asking for help. If I pass this module, I can go straight into 2nd year of my design course, not programming, design.[CODE]// Original source –

    // Andre La Mothe’s book, The Black Art of 3D Games Programming, PROG2_1.CPP

    // I have reduced this program to essentials and written a simple function,
    // screen_layout(), to show the use of colour and movement of the cursor.

    // main() is the last function in the listing (screen_layout() precedes it).
    // Substitute main() with anything you like. You can then use standard i/o
    // or move the cursor about and change colour just as you wish.

    // This isn’t going to rival a graphics engine – for that the current
    // second year module uses OpenGL which is a collection of C functions! –
    // but the use of colour and static / over-printing rather than scrolling
    // displays will make even simple turn-play games much more attractive.

    // Inclusion guards added so this file will only be compiled once within its own compilation module (within the object file)
    #ifndef __LAMOTHE_H__ // Added HH 26-11-’08
    #define __LAMOTHE_H__ // Added HH 26-11-’08

    // cjm 4-10-’01

    // INCLUDES ///////////////////////////////////////////////

    #include
    #include
    #include

    // DEFINES ////////////////////////////////////////////////

    #define MAX_X 77 // maximum x position for player
    #define SCROLL_POS 24 // the point that scrolling occurs

    // PROTOTYPES /////////////////////////////////////////////

    void Init_Graphics(void);
    void Set_Color(int fcolor, int bcolor);
    void Draw_String(int x,int y, char *string);

    // GLOBALS ////////////////////////////////////////////////

    // Variables declared extern because as projects grow in size possible variable name conflicts,
    // may occur if this header file is included in multiple files.
    extern CONSOLE_SCREEN_BUFFER_INFO con_info; // holds screen info // Added: extern, declare variable here but define it in lamothe.cpp file
    extern HANDLE hconsole; // handle to console // Added: extern, declare variable here but define it in lamothe.cpp file

    #endif // __LAMOTHE_H__ // Added HH 26-11-’08
    [/CODE]

    Now I’m wondering if most of you would agree this code is horrible to work with, that is why I’m asking for help. If I pass this module, I can go straight into 2nd year of my design course, not programming, design.

    Que?

    if ((k > 48) && (k < 58) && grid2[j] == true)
    cout << (k – 48);
    This will give an error because of the fact grid2 is not boolean but in fact int.

    should the code be therefore checking whatever is a valid input for the grid2? (either zero or non zero, but to be fair I have never really bothered with suduko!)

    Currently, if you run it, you will only be able to put numbers, the code is to make sure that a fixed value does not get overwritten, ie if a 9 is already there then that cannot be overwritten, however if the user inputs 9 then it can still be over written as grid2 has not saved the new value. Does that make sense?

    then surely grid2 array should instead be a boolean array matching the positions of grid 1 but flagging which numbers can accept input?

    That’s what I did attempt to do but what I did was wrong.

    Considering, I have no experience, I attempted to make grid2 a boolean by doing

    int i, j;

    int grid[9][9] =
    {{0, 5, 1, 7, 0, 0, 0, 6, 2},
    {9, 0, 0, 0, 0, 6, 0, 0, 8},
    {8, 3, 0, 0, 0, 2, 1, 0, 0},
    {7, 4, 9, 0, 0, 1, 8, 0, 0},
    {1, 0, 0, 0, 0, 0, 0, 0, 9},
    {0, 0, 2, 3, 0, 0, 6, 1, 4},
    {0, 0, 5, 8, 0, 0, 0, 4, 6},
    {2, 0, 0, 9, 0, 0, 0, 0, 7},
    {6, 7, 0, 0, 0, 3, 5, 9, 0}};

    [B]bool[/B] grid2[i][j] =
    {{0, 5, 1, 7, 0, 0, 0, 6, 2},
    {9, 0, 0, 0, 0, 6, 0, 0, 8},
    {8, 3, 0, 0, 0, 2, 1, 0, 0},
    {7, 4, 9, 0, 0, 1, 8, 0, 0},
    {1, 0, 0, 0, 0, 0, 0, 0, 9},
    {0, 0, 2, 3, 0, 0, 6, 1, 4},
    {0, 0, 5, 8, 0, 0, 0, 4, 6},
    {2, 0, 0, 9, 0, 0, 0, 0, 7},
    {6, 7, 0, 0, 0, 3, 5, 9, 0}};
    [/CODE]

    I know it’s wrong, but even when I asked the student helpers they wouldn’t tell me what I was doing wrong.[CODE]
    int i, j;

    int grid[9][9] =
    {{0, 5, 1, 7, 0, 0, 0, 6, 2},
    {9, 0, 0, 0, 0, 6, 0, 0, 8},
    {8, 3, 0, 0, 0, 2, 1, 0, 0},
    {7, 4, 9, 0, 0, 1, 8, 0, 0},
    {1, 0, 0, 0, 0, 0, 0, 0, 9},
    {0, 0, 2, 3, 0, 0, 6, 1, 4},
    {0, 0, 5, 8, 0, 0, 0, 4, 6},
    {2, 0, 0, 9, 0, 0, 0, 0, 7},
    {6, 7, 0, 0, 0, 3, 5, 9, 0}};

    bool grid2[j] =
    {{0, 5, 1, 7, 0, 0, 0, 6, 2},
    {9, 0, 0, 0, 0, 6, 0, 0, 8},
    {8, 3, 0, 0, 0, 2, 1, 0, 0},
    {7, 4, 9, 0, 0, 1, 8, 0, 0},
    {1, 0, 0, 0, 0, 0, 0, 0, 9},
    {0, 0, 2, 3, 0, 0, 6, 1, 4},
    {0, 0, 5, 8, 0, 0, 0, 4, 6},
    {2, 0, 0, 9, 0, 0, 0, 0, 7},
    {6, 7, 0, 0, 0, 3, 5, 9, 0}};
    [/CODE]

    I know it’s wrong, but even when I asked the student helpers they wouldn’t tell me what I was doing wrong.

    Can you give me a good suggestion for a class? I have no idea how it works.

    the boolean array should either contain true or false. True is usually -1 and false 0 but it could be compiler dependent.

    Unfortunately, I am old skool and learned programming just before C++ became popular (in fact I dropped out of uni a year before it started turning up) so am not as good with OOP – perhaps one of the younger people here can help.

0

Voices

30

Replies

Tags

This topic has no tags

Viewing 15 posts - 16 through 30 (of 32 total)
  • You must be logged in to reply to this topic.

Forums Life Computers, Gadgets & Technology Any C++ Programmers?