Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question: this will not run on my putty program because of this error: â setw â

ID: 3632633 • Letter: Q

Question

Question: this will not run on my putty program because of this error:

âsetwâ was not declared in this scope

what can i replace this with in order for the code to run? it is about half way down in bold, underlined and enlarged font.

#include <iostream>

#include <math.h>

#include <iomanip>

#define SIZE 3

using namespace std;

bool checkArray(int inputArray[][SIZE], int numRows, intnumCols)

{

// Each row, column and diagonal should be equal to

// (1/SIZE) * Sum(1 through SIZE^2)

int correctAnswer = (int)((pow(SIZE, 4.0) + pow(SIZE, 2.0))/(2 * (SIZE)));

cout << "Looking for: " << correctAnswer << " ";

for (int i = 0; i < numRows; i++)

{

int sumV = 0;

int sumH = 0;

// Scan row and column simultaneously

for (int j = 0; j < numCols; j++)

{

sumV = sumV + inputArray[j][i];

sumH = sumH + inputArray[i][j];

}

// Print out results for row and column

cout << "Sum for column " << i << ": " << sumV << " ";

cout << "Sum for row " << i << ": " << sumH << " ";

if (sumV != correctAnswer || sumH != correctAnswer)

return false;

}

int sumD1 = 0;

int sumD2 = 0;

for (int i = 0; i < numRows; i++)

{

sumD1 = sumD1 + inputArray[i][i];

sumD2 = sumD2 + inputArray[i][SIZE - i - 1];

}

cout << "Sum for diagonal 1: " << sumD1 << " ";

cout << "Sum for diagonal 2: " << sumD2 << " ";

if (sumD1 != correctAnswer || sumD2 != correctAnswer)

return false;

return true;

void printArray(int originalArray[][SIZE])

{

cout<<endl;

for( int i=0; i < SIZE;i++)

{

for(int j =0 ;j<SIZE;j++)

if(originalArray[i][j] == 0)

cout<< setw(5) <<'X';

else

cout<< setw(5) <<originalArray[i][j];

cout<<endl;

}

cout<<endl;

void populateArray(int originalArray[][SIZE], int numRows, intnumCols)

{

int row = 0,col = numCols/2, oldRow, oldCol;

for( int i = 1; i <= SIZE * SIZE; i++)

{

if(originalArray[row][col] != 0)

{

row = ++oldRow;

col = oldCol;

}

originalArray[row][col] = i;

printArray(originalArray);

oldRow = row --;

if(row < 0)

{

row = numRows -1;

oldCol = col++;

if( col >= numCols)

col = 0;

continue;

}

oldCol = col++;

if( col >= numCols)

col = 0;

}

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

// Main function: Creates a magic

// square

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

int main()

{

int counter = 0;

// Set the array to 0

int originalArray[SIZE][SIZE] = {0};

for (int i = 0; i < SIZE; i++)

{

for (int j = 0; j < SIZE; j++)

originalArray[i][j] = 0;

}

// Populate and print array

populateArray(originalArray, SIZE, SIZE);

// Checking to see if array is correct

if (checkArray(originalArray, SIZE, SIZE))

cout << "This is a magic square ";

else

cout << "This is not a magic square ";

return 0;

Explanation / Answer

Please insert .h extension in each header file like #include #include #include Because in some compilers they are taken by default but in some cases they are not.
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote