My assignment is to write a program that checks if a given 4x4 square of numbers is "magic"
I got the program to tell me if it IS a magic square.
If the square i enter is NOT a magic square, the program should tell me so. I used an else statement to do this but for some reason it's not working. When i enter a square that is not "magic" the program just ends without telling me so. any help would be awesome!
here is my code....
#include <iostream>
#include <string>
using namespace std;
int main() {
//Declare variables
int a, b, c, d;
int e, f, g, h;
int i, j, k, l;
int m, n, o, p;
//Tell user to enter magic square
cout << "Welcome to Robert's Magic Square Checker! Please enter your magic square:" << "\n";
//Lets user input the magic square
cin >> a; cin >> b; cin >> c; cin >> d;
cin >> e; cin >> f; cin >> g; cin >> h;
cin >> i; cin >> j; cin >> k; cin >> l;
cin >> m; cin >> n; cin >> o; cin >> p;
//if statements used to check if every line and column are equal
if (a + b + c + d == e + f + g + h)
if (e + f + g + h == i + j + k + l)
if (i + j + k + l == m + n + o + p)
if (m + n + o + p == a + f + k + p)
if (a + f + k + p == d + g + j + m)
{
//If every line and column is equal, the program will output this...
cout << "This was a magic square! Thank you!" << "\n";
}
else
{
//Otherwise, the program will output this...
//This is where i am having trouble!!!
cout << "This was not a magic square! Thank You!" << "\n";
}
}

New Topic/Question
Reply



MultiQuote







|