What's new

C & C++ C++ pa help po

kirakira32132

Forum Veteran
Established
pa help naman po, pag na complete at tama na yung sagot ayaw lumabas yung "congrats you finished the level". nag lo loop pa rin


C++:
#include <iostream>

#include <vector>



using namespace std;



void Answer(int arr[9][9])

{

    int row;

    int col;

    int ans;

    cout << "What row do you want to answer: ";

    cin >> row;

    cout << "What column do you want to answer: ";

    cin >> col;







    cout << "What is your answer: ";

    cin >> ans;

    arr[row - 1][col - 1] = ans;

}





void printSudoku(int arr[9][9]) {

    cout << "1 2 3    4 5 6    7 8 9" << endl;

    cout << "---------------------------" << endl;



    for (int r = 0; r < 9; r++) {

        for (int c = 0; c < 9; c++) {

            if (c == 3 || c == 6)

                cout << " | ";

            cout << arr[r][c] << " ";

        }

        if (r == 2 || r == 5) {

            cout << endl;

            for (int r = 0; r < 9; r++)

                cout << "---";

        }

        cout << endl;

    }

}





int  check(int arr[9][9], int check1)

{

    int check[9][9] = {

        {7, 3, 5, 6, 1, 4, 8, 9, 2},

        {8, 4, 2, 9, 7, 3, 5, 6, 1},

        {9, 6, 1, 2, 8, 5, 3, 7, 4},

        {2, 8, 6, 3, 4, 9, 1, 5, 7},

        {4, 1, 3, 8, 5, 7, 9, 2, 6},

        {5, 7, 9, 1, 2, 6, 4, 3, 8},

        {1, 5, 7, 4, 9, 2, 6, 8, 3},

        {6, 9, 4, 7, 3, 8, 2, 1, 5},

        {3, 2, 8, 5, 6, 1, 7, 4, 9}

    };



    if (check[9][9] = arr[9][9])

        check1 = 1;



    else

        check1 = 0;

    return check1;



}



int main() {



    int board[9][9] = {

        {7, 0, 0, 0, 0, 4, 0, 9, 0},

        {8, 0, 2, 9, 7, 0, 0, 0, 0},

        {9, 0, 1, 2, 0, 0, 3, 0, 0},

        {0, 0, 0, 0, 4, 9, 1, 5, 7},

        {0, 1, 3, 0, 5, 0, 9, 2, 0},

        {5, 7, 9, 1, 2, 0, 0, 0, 0},

        {0, 0, 7, 0, 0, 2, 6, 0, 3},

        {0, 0, 0, 0, 3, 8, 2, 0, 5},

        {0, 2, 0, 5, 0, 0, 0, 0, 0}

    };

    int check1 = 1;

    while (check1 = 1)

    {

        printSudoku(board);

        Answer(board);

        check(board, check1);

    }

    cout << "congrats you finished the level";



    return 0;

}
 
Last edited:
Solution
C++:
#include <iostream>
#include <vector>

using namespace std;

int rowSum(int array[9][9]){
            int sum=0;
            for(int i=0; i<9; i++)
                for(int j=0;j<9; j++)
                    sum+=array[i][j];
            return sum;
}
        
void Answer(int arr[9][9])
{
    int row = 0;
    int col = 0;
    int ans = 0;
    cout << "What row do you want to answer: ";
    cin >> row;
    cout << "What column do you want to answer: ";
    cin >> col;



    cout << "What is your answer: ";
    cin >> ans;
    arr[row - 1][col - 1] = ans;

}


void printSudoku(int arr[9][9]) {
    cout << "1 2 3    4 5 6    7 8 9" << endl;
    cout << "---------------------------" << endl;

    for (int r = 0; r < 9; r++) {
        for...
C++:
#include <iostream>
#include <vector>

using namespace std;

int rowSum(int array[9][9]){
            int sum=0;
            for(int i=0; i<9; i++)
                for(int j=0;j<9; j++)
                    sum+=array[i][j];
            return sum;
}
        
void Answer(int arr[9][9])
{
    int row = 0;
    int col = 0;
    int ans = 0;
    cout << "What row do you want to answer: ";
    cin >> row;
    cout << "What column do you want to answer: ";
    cin >> col;



    cout << "What is your answer: ";
    cin >> ans;
    arr[row - 1][col - 1] = ans;

}


void printSudoku(int arr[9][9]) {
    cout << "1 2 3    4 5 6    7 8 9" << endl;
    cout << "---------------------------" << endl;

    for (int r = 0; r < 9; r++) {
        for (int c = 0; c < 9; c++) {
            if (c == 3 || c == 6)
                cout << " | ";
            cout << arr[r][c] << " ";
        }
        if (r == 2 || r == 5) {
            cout << endl;
            for (int r = 0; r < 9; r++)
                cout << "---";
        }
        cout << endl;
    }
}


int  check(int arr[9][9], int check1)
{
    int check[9][9] = {
        {7, 3, 5, 6, 1, 4, 8, 9, 2},
        {8, 4, 2, 9, 7, 3, 5, 6, 1},
        {9, 6, 1, 2, 8, 5, 3, 7, 4},
        {2, 8, 6, 3, 4, 9, 1, 5, 7},
        {4, 1, 3, 8, 5, 7, 9, 2, 6},
        {5, 7, 9, 1, 2, 6, 4, 3, 8},
        {1, 5, 7, 4, 9, 2, 6, 8, 3},
        {6, 9, 4, 7, 3, 8, 2, 1, 5},
        {3, 2, 8, 5, 6, 1, 7, 4, 9}
    };

    if (rowSum(check) == rowSum(arr)){
        cout << "congrats you finished the level";
        exit(1);
    }
    else{
        check1 = 1;
    }
    return check1;
    {

    }
}

int main() {

    int board[9][9] = {
        {7, 0, 0, 0, 0, 4, 0, 9, 0},
        {8, 0, 2, 9, 7, 0, 0, 0, 0},
        {9, 0, 1, 2, 0, 0, 3, 0, 0},
        {0, 0, 0, 0, 4, 9, 1, 5, 7},
        {0, 1, 3, 0, 5, 0, 9, 2, 0},
        {5, 7, 9, 1, 2, 0, 0, 0, 0},
        {0, 0, 7, 0, 0, 2, 6, 0, 3},
        {0, 0, 0, 0, 3, 8, 2, 0, 5},
        {0, 2, 0, 5, 0, 0, 0, 0, 0}
    };
    int check1 = 1;
    while (check1 = 1)
    {
        printSudoku(board);
        Answer(board);
        check(board, check1);
    }

    return 0;
}
 
Solution

Similar threads

Back
Top