Rate my assignment and give feedback, please

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 947 Views - Last Post: 18 November 2019 - 05:52 PM Rate Topic: -----

#1 PendeJoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 09-October 19

Rate my assignment and give feedback, please

Posted 15 November 2019 - 02:37 AM

Hey,
i would love some feedback on my assignment and i appreciate all the replys!
And also if i in your opinion accomplish the extra credits, thanks !

Requirements:

Use nested for-loop to find the sum of each row and column.
DON'T compare each sum == 15. DON'T assume the desired total is 15.
Display the programmer info at the beginning of the output
Include the function prototypes before the main()
All functions definitions should be after the main()

[Extra Credits 25 points]
bool validateArray(const int array[][COLS], int rows)

#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

const int COLS = 3;
const int ROWS = 3;
bool checkLoShuSquare(const int arr[][COLS], int rows);
void showArray(const int [][COLS], int);
void fillArray(int arr[][COLS], int rows);
bool validateArray(const int arr[][COLS], int rows);
void programmerInfo();

int main()
{
    int LoShu[ROWS][COLS] = {   {4, 9, 2},
                                {3, 5, 7},
                                {8, 1, 6}};
    int square1[ROWS][COLS] = { {1, 2, 3},
                                {4, 5, 6},
                                {7, 8, 9}};
    int square2[ROWS][COLS] = { {1, 4, 7},
                                {2, 5, 8},
                                {3, 6, 9}};
    int randomS[ROWS][COLS];

    programmerInfo();
    cout << "**Test the first square**\n";
    showArray(LoShu,COLS);
    if(validateArray(LoShu,ROWS)!=1){
        cout << "It is NOT a 3 x 3 array contained the numbers 1~9 exactly.\n";
    }
    if(checkLoShuSquare(LoShu, ROWS)==1){
    cout << "It is a Lo Shu Magic Square!\n";
    } else{
    cout << "It is NOT a Lo Shu Magic Square!\n";
    }

    cout << "\n**Test the second square**\n";
    showArray(square1, ROWS);
    if(validateArray(square1,ROWS)!=1){
        cout << "It is NOT a 3 x 3 array contained the numbers 1~9 exactly.\n";
    }
    if(checkLoShuSquare(square1,ROWS)==1){
    cout << "It is a Lo Shu Magic Square!\n";
    } else{
    cout << "It is NOT a Lo Shu Magic Square!\n";
    }

    cout << "\n**Test the third square**\n";
    showArray(square2, ROWS);
    if(validateArray(square2,ROWS)!=1){
        cout << "It is NOT a 3 x 3 array contained the numbers 1~9 exactly.\n";
    }
    if(checkLoShuSquare(square2,ROWS)==1){
    cout << "It is a Lo Shu Magic Square!\n";
    } else{
    cout << "It is NOT a Lo Shu Magic Square!\n";
    }

    cout << "\n**Test the random square**\n";
    srand((unsigned)time(0));
    fillArray(randomS, ROWS);
    showArray(randomS, ROWS);
    if(validateArray(randomS,ROWS)!=1){
        cout << "It is NOT a 3 x 3 array contained the numbers 1~9 exactly.\n";
    }
    if(checkLoShuSquare(randomS,ROWS)==1){
        cout << "It is a Lo Shu Magic Square!\n";
    } else{
    cout << "It is NOT a Lo Shu Magic Square!\n";
    }

    return 0;
}

void showArray(const int array[][COLS], int rows){
  int total = 0;
  int colTotal[COLS+1] = {0};
   for (int x = 0; x < rows; x++){
      total = 0;
      for (int y = 0; y < COLS; y++){
         cout << setw(3) << array[x][y];
         total += array[x][y];
         colTotal[y] += array[x][y];
      }
      cout << endl;
   }
}

void fillArray(int arr[][COLS], int rows){
    for (int i=0;i<rows;i++){
        for(int z=0;z<COLS;z++){
            arr[i][z] = rand() % 10;
        }
    }
}

bool validateArray(const int arr[][COLS], int rows){
    for(int i=0;i<COLS;i++){
        for(int x=0; x<rows;x++){
            if(arr[i][x]<1||arr[i][x]>9)
        return false;
        }
    }
return true;
}

bool checkLoShuSquare(const int arr[][COLS], int rows){
    int value=0;
    for(int i=0;i<COLS;i++){
        value+= arr[0][i];
    }
    for(int a=1;a<rows;a++){
        int var=0;
        for(int b=0;b<COLS;b++){
            var+= arr[a][b];
        }
        if(var!=value){
            return false;
        }
    }
    for(int c=0;c<COLS;c++){
        int var2=0;
        for(int d=0;d<rows;d++){
            var2+=arr[c][d];
        }
        if(var2!=value){
            return false;
        }
    }
    for(int e=0;e<COLS;e++){
        int diagLeft=0;
        for(int f=0;f<rows;f++){
            diagLeft+=arr[e][f];
        }
        if(diagLeft!=value){
            return false;
        }
    }
    for(int g=2;g>0;g--){
        int diagRight=0;
        for(int h=0;h<rows;h++){
            diagRight+=arr[g][h];
        }
        if(diagRight!=value){
            return false;
        }
    }
return true;
}


void programmerInfo(){
   cout << left << setw(17) << "Programmer Name:" << setw(7) << right << "John Smith\n";
   cout << left << setw(20) << "Programmer ID:" << setw(10) << right <<"1234567\n";
}


Is This A Good Question/Topic? 0
  • +

Replies To: Rate my assignment and give feedback, please

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6823
  • View blog
  • Posts: 28,274
  • Joined: 12-December 12

Re: Rate my assignment and give feedback, please

Posted 15 November 2019 - 03:59 AM

Have you handed in your assignment?
Was This Post Helpful? 0
  • +
  • -

#3 PendeJoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 09-October 19

Re: Rate my assignment and give feedback, please

Posted 15 November 2019 - 04:02 AM

No, i would like to get some feedback and see if there is anything ive missed, not asking for any answers just feedback :)
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7136
  • View blog
  • Posts: 24,244
  • Joined: 05-May 12

Re: Rate my assignment and give feedback, please

Posted 15 November 2019 - 09:32 AM

I'm sorry if these critiques will come across as harsh, but I hope it will help you get a better grade.
  • Essentially duplicate code between lines 28-37, 39-48, 50-59, 61-72. If you take time to create a helper function that encapsulates the common code among these 4 sections, it will go a long way towards making the code easier to read and understand.
  • For extra bonus in getting rid of the duplicated code, you can take advantage of multi-dimensional arrays and have an array of squares. This will let you then just loop over the 4 different squares.
  • Inconsistent naming used for iterators variables. Across your functions showArray(), fillArray(), validateArray(), and checkLoShuSquare() methods, sometimes you use different variable names for the rows and columns index variables. It would be much better if you are consist like always using i and j, or x and y, or row and col instead of the current mishmash that you have.
  • Inconsistent indentation style. Lines 34, 36, 45, 47, 56, 58, 71, 78-88, 103, 106, 150
  • Inconsistent OTBS application. Recall that in One True Brace Style, there should be a space in front of the opening curly brace. Also your main() is not following OTBS. And if you are really an OTBS believer (I prefer Allman personally), then what do you do about lines 16-24?
  • Inconsistent use of whitespace / not using whitespace causing condensed text. Lines 29, 30, 33, 41, 44, 52, 55, 65, 68, 79, 92-93, 100-102, 110-149
  • Keep constant declarations (Lines 6-7) separate from function prototypes (Lines 8-12) by using whitespace.
  • Depending on whether your a teacher is a one-way-one-way-out-of-a-function type of person, you may want to remove the multiple exit points in checkLoShuSquare().
  • showArray() seems to compute total and colTotal[] values, yet does nothing with these computed values. Is this intended?
  • fillArray() looks like it can potentially put in a zero for an element. Is this intended?
  • It's unclear to me why your various functions take a rows parameter when you have a constant ROWS. Why not just use the constant since you are using the COLS constant for the array parameter?
  • You are not using your constants for your error message. e.g. "It is not a 3 x 3 array ..." So if ever you change your constants, you also have to change your error message.
  • Why are you still using the old C-style rand() method when Modern C++ has a random number generator as part of its standard library?

Was This Post Helpful? 1
  • +
  • -

#5 PendeJoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 09-October 19

Re: Rate my assignment and give feedback, please

Posted 15 November 2019 - 05:00 PM

Thanks for the feedback!

After all your feedback I've made some changes and it looks better structured now, this is my first course of programming so I didn't know there are different type of coding variants. In fact there is alot I yet don't know but I'm working my way there! Which also explains why I use "rand()".

I couldn't figure out "For extra bonus in getting rid of the duplicated code, you can take advantage of multi-dimensional arrays and have an array of squares. This will let you then just loop over the 4 different squares." since we haven't been through multi-dimensional arrays yet, we are at 2D arrays at the moment.

Also how would I remove the multiple exit points and make it to one? I've tried with creating a variable (lets say "trueVal")to add up 1 for each time it is true, at the end ill do
if(trueVal != 7) { return false; }
(7 becuase that's how many times the statement is checked.) any inputs there?



Here is the updated version:

#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

const int COLS = 3;
const int ROWS = 3;

bool checkLoShuSquare(const int arr[ROWS][COLS]);
bool validateArray(const int arr[ROWS][COLS]);
void showArray(const int [ROWS][COLS]);
void fillArray(int arr[ROWS][COLS]);
void programmerInfo();
void simple(int ,int);

int main()
{
    int LoShu[ROWS][COLS] = {{4, 9, 2}, {3, 5, 7}, {8, 1, 6}};
    int square1[ROWS][COLS] = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9} };
    int square2[ROWS][COLS] = { {1, 4, 7}, {2, 5, 8}, {3, 6, 9} };
    int randomS[ROWS][COLS];
    int valid = 0;
    int check = 0;

    programmerInfo();

    cout << "**Test the first square**\n";

    showArray(LoShu);
    valid = validateArray(LoShu);
    check = checkLoShuSquare(LoShu);
    simple(valid, check);

    cout << "\n\n**Test the second square**\n";

    showArray(square1);
    valid = validateArray(square1);
    check = checkLoShuSquare(square1);
    simple(valid, check);

    cout << "\n\n**Test the third square**\n";

    showArray(square2);
    valid = validateArray(square2);
    check = checkLoShuSquare(square2);
    simple(valid, check);

    cout << "\n\n**Test the random square**\n";

    srand((unsigned)time(0));
    fillArray(randomS);
    showArray(randomS);
    valid = validateArray(randomS);
    check = checkLoShuSquare(randomS);
    simple(valid, check);

    return 0;
}

void showArray(const int arr[ROWS][COLS])
{
   for (int x = 0; x < ROWS; x++) {
      for (int y = 0; y < COLS; y++) {
         cout << setw(3) << arr[x][y];
      }
      cout << endl;
   }
}

void fillArray(int arr[ROWS][COLS])
{
    for (int i = 0; i < ROWS; i++) {
        for(int z = 0;z < COLS; z++) {
            arr[i][z] = rand() % 10;
        }
    }
}

bool validateArray(const int arr[ROWS][COLS])
{
    for(int i = 0; i < COLS; i++) {
        for(int x = 0; x < ROWS; x++) {
            if(arr[i][x] < 1 || arr[i][x] > 9)
        return false;
        }
    }
return true;
}

bool checkLoShuSquare(const int arr[ROWS][COLS])
{
    int value = 0;
    for(int x = 0; x < COLS; x++) {
        value += arr[0][x];
    }
    for(int y = 1; y < ROWS; y++) {
        int var = 0;
        for(int x = 0; x < COLS; x++) {
            var += arr[y][x];
        }
        if(var != value) {
            return false;
        }
    }
    for(int x = 0; x < COLS; x++) {
        int var2 = 0;
        for(int y = 0; y < ROWS; y++) {
            var2 += arr[x][y];
        }
        if(var2 != value) {
            return false;
        }
    }
    for(int x = 0; x < COLS; x++) {
        int diagLeft = 0;
        for(int y = 0; y < ROWS; y++) {
            diagLeft += arr[x][y];
        }
        if(diagLeft != value) {
            return false;
        }
    }
    for(int x = 2; x > 0; x--) {
        int diagRight = 0;
        for(int y = 0; y < ROWS; y++) {
            diagRight += arr[x][y];
        }
        if(diagRight != value) {
            return false;
        }
    }
return true;
}

void simple(int validation, int check)
{
    if(validation != 1) {
        cout << "It is NOT a 3 x 3 array contained the numbers 1~9 exactly.\n";
    }
    if(check == 1) {
    cout << "It is a Lo Shu Magic Square!";
    } else {
    cout << "It is NOT a Lo Shu Magic Square!";
    }
}

void programmerInfo()
{
    cout << left << setw(17) << "Programmer Name:" << setw(7) << right << "John Smith\n";
    cout << left << setw(20) << "Programmer ID:" << setw(10) << right <<"1234567\n";
}

Was This Post Helpful? 0
  • +
  • -

#6 PendeJoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 09-October 19

Re: Rate my assignment and give feedback, please

Posted 15 November 2019 - 05:10 PM

also changed my function to
 void simple(int, int, const int ROWS, const int COLS)

since you're right, if the constants change I would have to change the error message manually :smile2:
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7136
  • View blog
  • Posts: 24,244
  • Joined: 05-May 12

Re: Rate my assignment and give feedback, please

Posted 16 November 2019 - 08:07 AM

Unless you know what you are doing shadowing variables and constants is a bad idea. In your latest simple() function in post #6, you are shadowing the global constants. Imagine what confusion will ensure if some calls simple(1,2,3,4). You are better of with your original code from post #5, and simply use the global constants.

I have other comments about the updated code from post #8, but I am on my phone right now. I'll post back later. I'll also respond regarding the multiple exits and how to do single exit both the easy way, and the hard way.

For now, good job doing some of the code cleanup and refactoring to try to minimize duplicate code. I suggest taking a second pass at removing duplicate code by moving that calls to show and validate into simple() and just pass in the array as well as the title string that you print out. I also suggest renaming simple() to something like testLoShuSquare() to continue on your path of using meaningful identifiers.

Also good job making some of the whitespace formatting more consistent.
Was This Post Helpful? 1
  • +
  • -

#8 PendeJoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 09-October 19

Re: Rate my assignment and give feedback, please

Posted 16 November 2019 - 03:53 PM

I gotta say I really appreciate you taking your time on giving me the feedback I need! I hope that one day I can be able to help other people with their confusions too !
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7136
  • View blog
  • Posts: 24,244
  • Joined: 05-May 12

Re: Rate my assignment and give feedback, please

Posted 16 November 2019 - 07:09 PM

Here's my feedback for the code posted in #5:
  • For loops over lines 114-122 and 123-131 are not actually checking the diagonals. In fact, lines 123-131 is doing exactly the same work as lines 105-113.
  • Essentially duplicate code between lines 27-32, 34-39, 41-46, 48-55. Consider letting the code for printing out the title, and the calls to validateArray(), and checkLoShuSquare() live inside simple(). Just pass in the title string and the array.
  • Poor type consistency: valid and check are declared as integers, but validateArray() and checkLoShuSquare() return booleans.
  • Inconsistent indentation style. Lines 63-66, 87, 141, 143.
  • Inconsistent formatting. Line 18 vs 19-20
  • Need better identifier names. Lines 92, 97, 102, 135.

Was This Post Helpful? 1
  • +
  • -

#10 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7136
  • View blog
  • Posts: 24,244
  • Joined: 05-May 12

Re: Rate my assignment and give feedback, please

Posted 16 November 2019 - 07:59 PM

As for the multiple exit points. In Modern C++, there is not as much adherence to the old FORTRAN and C convention of only having one entry point and and one exit point for any functions. The reason why the "rule" existed for experience programmers for those procedural languages is because as functions got bigger and bigger, a common programmer error is the failure to clean up properly before exiting out of a function. The reason why functions got so large is because with older computers, there was a significant and measurable overhead for calling functions. So instead of writing another function and calling it, programmers back then would keep piling up more and more code into any existing functions. The reason why early C++ programmers also adopted this rule is because early C++ used to be written as C-with-classes but still in a procedural manner rather than fully taking advantage of the object oriented approach to programming. Fast forward to now where C++ programmers have learned to use C++ in better ways, we actually recommend the use of RAII (Resource Acquisition Is Initialization). RAII takes full advantage of scopes, so when a scope is entered something is allocation or initialized, and then exiting the scope will automatically do the appropriate cleanup. Also another development is that computers have gotten faster (and compilers and linkers smarter) to minimize the impact of function calls. So instead of large monolithic functions spanning thousands of lines, the modern rule of thumb is that if a function is longer than 20-25 lines, you probably are not following the SRP (single responsibility principle) and you should break up the function into smaller functions.

Anyway after that historical side trip, if you still really want to have one entry point and one exit point, there are two general approaches. The first takes advantage of a success flag, while the latter takes advantage of Boolean short-circuiting and the trend towards smaller functions.

As an example, let's start off with pseudo code that looks like this:
bool isValidLoShuSquare()
{
    commonSum = compute sum of first row

    for each row
        sum = compute sum of row
        if sum != commonSum
            return false

    for each column
        sum = compute sum of column
        if sum != commonSum
            return false

    sum = compute sum of northwest to southeast diagonal
    if sum != commonSum
        return false

    sum = compute sum of northeast to southwest diagonal
    if sum != commonSum
        return false

    return true
}



Using the success flag we would do something like:
bool isValidLoShuSquare()
{
    success = true
    commonSum = compute sum of first row

    for each row and success == true
        sum = compute sum of row
        if sum != commonSum
            success = false

    for each column and success == true
        sum = compute sum of column
        if sum != commonSum
            success = false

    if success == true
        sum = compute sum of northwest to southeast diagonal
        if sum != commonSum
            success = false

    if success == true
        sum = compute sum of northeast to southwest diagonal
        if sum != commonSum
            success = false

    return success
}



And with the smaller functions and short circuiting it would something like this:
bool isValidLoShuSquare()
{
    commonSum = compute sum of first row

    return allRowsEqualTo(commonSum) AND
           allColumnsEqualTo(commonSum) AND
           commonSum == sumOfNorthWestToSouthEast() AND
           commonSum == sumOfNorthEastToSouthWest()
}

int sumOfNorthWestToSouthEast()
{
    return compute sum of northwest to southeast diagonal
}

int sumOfNorthEastToSouthWest()
{
    return compute sum of northeast to southwest diagonal
}

bool allRowsEqualTo(int commonSum)
{
    success = true
    for each row and success == true
        sum = compute sum of row
        if sum != commonSum
            success = false
    return success
}

bool allRowsEqualTo(int commonSum)
{
    success = true
    for each column and success == true
        sum = compute sum of column
        if sum != commonSum
            success = false
    return success
}



Yes, in all the code above the sum of the first row is recomputed. This can be written more optimally by having parameters or hardcoding to skip the first row, but that will start adding complexity to the code. If profiling proves that recomputing the first row is a significant drain on performance, then it maybe worth adding to the complexity. I feel though that modern compilers know how to take advantage of vector addition at the CPU level to quickly compute the sum of a row.
Was This Post Helpful? 1
  • +
  • -

#11 PendeJoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 09-October 19

Re: Rate my assignment and give feedback, please

Posted 16 November 2019 - 11:28 PM

After fixing the part where I misscalculated the diagonal sum, I changed my function bool checkSquare(const int arr[ROWS][COLS]); to the following:

bool checkLoShuSquare(const int arr[ROWS][COLS])
{
    int trueVal = true;
    int refVal = 0;
    int diagLeft = 0;
    int diagRight = 0;

    for(int x = 0; x < COLS; x++) { //sets the value to which refer
        refVal += arr[0][x];
    }
    for(int y = 0; y < ROWS; y++) { //checks the horizontal value
        int rowVal = 0;
        for(int x = 0; x < COLS; x++) {
            rowVal += arr[y][x];
        }
        if(rowVal != refVal) {
            trueVal = false;
        }
    }
    for(int x = 0; x < ROWS; x++) { //checks the vertical value
        int colVal = 0;
        for(int y = 0; y < COLS; y++) {
            colVal += arr[x][y];
        }
        if(colVal != refVal) {
            trueVal = false;
        }
    }
    for(int y = 0; y < ROWS; y++) { //checks the diagonal value from the left
        diagLeft += arr[y][y];
    }
    if(diagLeft != refVal) {
        trueVal = false;
    }

    int z = COLS - 1;
    for(int y = 0; y < ROWS; y++) { //checks the diagonal value form the right
        diagRight += arr[z][y];
        z--;
    }
    if(diagRight != refVal || refVal == 0) {
        trueVal = false;
    }
    return trueVal;
}


and I feel pretty satisfied with this .cpp, I got alot of information from the links you sent, is there any place here in D.I.C. where I can improv my knowledge? Still new to this forum !
Was This Post Helpful? 0
  • +
  • -

#12 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7136
  • View blog
  • Posts: 24,244
  • Joined: 05-May 12

Re: Rate my assignment and give feedback, please

Posted 17 November 2019 - 01:28 AM

This is what happens when you pick poorly named identifiers, and put in unnecessary comments -- you end up with a bug:
int z = COLS - 1;
for(int y = 0; y < ROWS; y++) { //checks the diagonal value form the right
    diagRight += arr[z][y];
    z--;
}



The code is not really computing the sum of the diagonal from the right. z in this case is actually the column number, but you are using it as the row number. The comment unfortunately fools the reader into thinking that all is well.

Consider what happens if it was written as:
for(int row = 0, col = COLS - 1; row < ROWS; row++, col--) {
    diagRight += arr[col][row];
}


Now this sticks out as a sore thumb that something is wrong: diagRight += arr[col][row];. It should really be diagRight += arr[row][col];.

The same issue exists here:
for(int x = 0; x < ROWS; x++) { //checks the vertical value
    int colVal = 0;
    for(int y = 0; y < COLS; y++) {
        colVal += arr[x][y];
    }
    if(colVal != refVal) {
        trueVal = false;
    }
}


The comment fools the reader into thinking that the columns are being summed up, but a closer read of the code shows that colVal is actually the sum of each row.
Was This Post Helpful? 2
  • +
  • -

#13 PendeJoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 09-October 19

Re: Rate my assignment and give feedback, please

Posted 17 November 2019 - 04:07 AM

Oh about that, I meant to do it this way:

int z = COLS - 1;
for(int y = 0; y < ROWS; y++) { //checks the diagonal value form the right
    diagRight += arr[y][z];
    z--;
}


I must've forgotten to go through everything again. When I run the .cpp I still get a valid respons,
it's just that instead of going from top left to bottom right it goes from bottom right to top left.
After having a closer look at it I recognize this, I should read my code carefully next time !
Was This Post Helpful? 0
  • +
  • -

#14 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7136
  • View blog
  • Posts: 24,244
  • Joined: 05-May 12

Re: Rate my assignment and give feedback, please

Posted 17 November 2019 - 07:10 PM

There is a reason why the validateArray() function is worth 25 extra bonus points. There is more to the validation than just doing a range check of values from 1-9. The values of 1 to 9 is true only if ROWS == COLS == 3. If you have a 5x5 magic square, the range will be from 1 to 25. Furthermore, in a traditional magic square, a value should only appear once.
Was This Post Helpful? 0
  • +
  • -

#15 PendeJoe   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 09-October 19

Re: Rate my assignment and give feedback, please

Posted 17 November 2019 - 11:59 PM

so then it should be something like this:

bool validateArray(const int arr[ROWS][COLS])
{
    for(int i = 0; i < ROWS; i++) {
        for(int x = 0; x < COLS; x++) {
            if(arr[i][x] < 1 || arr[i][x] > ROWS * COLS)
        return false;
        }
    }
    return true;
}


just to verify the size of the range
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2