/*
* lab04a.c
* Author: Student 2
* Lecure, Lab Section: 3, 3
* Lab  #: 4
* Submitted on: September 20th, 2018
*
* Purpose: This program will let the uesr input a magic square and will check if it is a magic square or not. If it is not, it will also output erroneous rows, columns, and diagonals.
*
* Academic Honesty Declaration:
* The following code represents my own work and I have neither received nor given assistance that violates the collaboration policy posted with this assignment. I have not copied or modified code from any other source other than the lab assignment, course textbook, or course lecture slides. Any unauthorized collaboration or use of materials not permitted will be subject to academic integrity policies of Clemson University and CPSC 1010/1011.
*
* I acknowledge that this lab assignment is based upon an assignment created by Clemson University and that any publishing or posting of this code is prohibited unless I receive written permission from Clemson University.
*/
#include <stdio.h>
#include <stdbool.h>

int main(void){
	//Initialize the variables
	int entry00 = 0, entry01 = 0, entry02 = 0;
	int entry10 = 0, entry11 = 0, entry12 = 0;
	int entry20 = 0, entry21 = 0, entry22 = 0;
	
	bool isMagicSquare = true;

	//Prompt the user to enter the values.
	printf("\nEnter in the values: ");

	//Scan the values that the user inputs
	scanf("%d", &entry00);
	scanf("%d", &entry01);
	scanf("%d", &entry02);
	scanf("%d", &entry10);
	scanf("%d", &entry11);
	scanf("%d", &entry12);
	scanf("%d", &entry20);
	scanf("%d", &entry21);
	scanf("%d", &entry22);

	//Print the values
	printf("\nYou entered:\n");
	printf("%d %d %d\n", entry00, entry01, entry02);
	printf("%d %d %d\n", entry10, entry11, entry12);
	printf("%d %d %d\n\n", entry20, entry21, entry22);

	//Check every row
	printf("Analyzing...\n");

	//Every row, column, and diagonal check functions identically to this one.
	if(entry00 + entry01 + entry02 != 15){ //Check if the sum is not 15, meaning it is an incorrect row
		isMagicSquare = false; //Flag the square as not a magic square
		printf("[%d, %d, %d] does not work!\n", entry00, entry01, entry02); //Print out the incorrect row
	}
	if(entry10 + entry11 + entry12 != 15){
		isMagicSquare = false;
		printf("[%d, %d, %d] does not work!\n", entry10, entry11, entry12);
	}
	if(entry20 + entry21 + entry22 != 15){
		isMagicSquare = false;
		printf("[%d, %d, %d] does not work!\n", entry20, entry21, entry22);
	}
	
	//Check every column
	if(entry00 + entry10 + entry20 != 15){
		isMagicSquare = false;
		printf("Column 0 does not work!\n");
	}
	if(entry01 + entry11 + entry21 != 15){
		isMagicSquare = false;
		printf("Column 1 does not work!\n");
	}
	if(entry02 + entry12 + entry22 != 15){
		isMagicSquare = false;
		printf("Column 2 does not work!\n");
	}
	
	//Check every diagonal
	if(entry00 + entry11 + entry22 != 15){
		isMagicSquare = false;
		printf("Diagonal [%d, %d, %d] does not work!\n", entry00, entry11, entry22);
	}
	if(entry20 + entry11 + entry02 != 15){
		isMagicSquare = false;
		printf("Diagonal [%d, %d, %d] does not work!\n", entry20, entry11, entry02);
	}

	//Print out whether the square is magic
	if(isMagicSquare){
		printf("\nThis is a magic square!\n");
	}
	else{
		printf("\nThis is not a magic square!\n");
	}


	return(0);
}
