Question

It is a C++ assignment. i wrote the program but it gives me error. please i...

It is a C++ assignment. i wrote the program but it gives me error. please i need help to fix my following assignment. i posted the assignment too.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is code:

#include <iostream>

#include <stdlib.h>

using namespace std;

int main()

{

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

int sumRow, sumCol;

int diag1 = 0, diag2 = 0;

//

// ─────────────────────────────────────────────────────── CHECKING DIAGONALS ─────

//

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

{

diag1 += magic[i][i];

diag2 += magic[i][2 - i];

}

if (diag1 != 15 || diag2 != 15)

{

cout << "Invalid Magic numbers\n";

exit(0);

}

//

// ────────────────────────────────────────────────── CHEKING ROW AND COLUMNS ─────

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

{

sumRow = 0;

sumCol = 0;

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

{

sumRow += magic[i][j];

sumCol += magic[j][i];

}

if (sumRow != 15 || sumCol != 15)

{

cout << "Invalid Magic numbers\n";

exit(0);

}

}

cout << "Valid magic numbers!\n";

}

Output:

Valid magic numbers!

Add a comment
Know the answer?
Add Answer to:
It is a C++ assignment. i wrote the program but it gives me error. please i...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone please help me to fix this APA citations format? I wrote this citation and...

    Can someone please help me to fix this APA citations format? I wrote this citation and my teacher commented "check APA for reference heading" Herzig, C. T., Stone, P. W., Castle, N., Pogorzelska-Maziarz, M., Larson, E. L., & Dick, A. W. (2016). Infection prevention and control programs in US nursing homes: results of a national survey. Journal of the American Medical Directors Association, 17(1), 85-88.

  • NEED SOME HELP WRITING THIS C++ PROGRAM...so far I wrote this program for (r-1; r <-5;...

    NEED SOME HELP WRITING THIS C++ PROGRAM...so far I wrote this program for (r-1; r <-5; r++) output for (r = 1; r<= 5; r++) output NEED HELP WITH THIS PATTERN:

  • When I run my program it gives me these exceptions and I don't know what it...

    When I run my program it gives me these exceptions and I don't know what it means by it : Exception in thread "main" java.lang.NumberFormatException: For input string: "Code" Does anyone know what I need to change for this to work?

  • This is my python assignment You wrote a program to prompt the user for hours and...

    This is my python assignment You wrote a program to prompt the user for hours and rate per hour to compute gross pay. Also your pay computation to give the employee 1.5 times the hourly rate for hours worked above 40 hours. Enter Hours: 45 Enter Rate: 10 Pay: 475.0 (475 = 40 * 10 + 5 * 15) Rewrite your pay program using try and except so that your program handles non-numeric input gracefully. Enter Hours: 20 Enter Rate:...

  • Please help me I need someone to help me with this program in C# please Write...

    Please help me I need someone to help me with this program in C# please Write a program named Admission for a college’s admissions office. The user enters a numeric high school grade point average (for example, 3.2) and an admission test score. Display the message Accept if the student meets either of the following requirements: A grade point average of 3.0 or higher, and an admission test score of at least 60 A grade point average of less than...

  • Help about c++ assignment, the due date was very soon right now

    I am still struggling to do this assignment using c++ visual studios right now, i need help before the deadlineThe questions are in the google docs and I need help now because the due date was very soon at the 30th of November 2021 so I need help as soon as possible about the program on visual studios c++ and make the program quick before the due date right now.Now I got 11 people request to get the answer on...

  • Please help me ead to toe assessement of a patient that as a Pancreatitis, i wrote"The...

    Please help me ead to toe assessement of a patient that as a Pancreatitis, i wrote"The expected finding during head to toe assessment in the patient are, vomiting, fever and rapid pulse, dry mucous membrane, rigid abdomen, tachycardia, hypotension, bruising in the flank and around the umbilicus" but my instroctor those not want that she want something from General Status Vital signs Head, Ears, Eyes, Nose, Throat Neck Respiratory Cardiac Abdomen Pulses Extremities Skin Neurological Please help as i do...

  • I need help with my assignment. It is a java program. Please make it as simple...

    I need help with my assignment. It is a java program. Please make it as simple as you can. Create an ArrayList with elements the objects of previous class. Using a simple loop populate the ArrayList with data from some arrays with data, or from console. Use a loop with iterator and write the information in a File using PrintWriter. Use this address for the file (c:\\result\\MyData.txt). Use the Scanner class to display the content of the file on console.

  • Question: Please help me to correct answer , I don't understand. This is my last chance....

    Question: Please help me to correct answer , I don't understand. This is my last chance. please help me. 1s... Please help me to correct answer , I don't understand. This is my last chance. please help me. 1st pic: qustion 2nd pic: professor said that fix it. (NEED HELP) 3rd pic: what I answered... please help me. Thank you so so s os o much!!! I am not sure what teacher wants me to put separate....... please help me.(...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT