fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void MagicBox();
  5.  
  6. int main () {
  7.  
  8. MagicBox();
  9.  
  10. return 0;
  11. }
  12.  
  13. void MagicBox() {
  14. int displayR,displayC;
  15. int arrEnt1D,arrEnt2D,test,count,count1,loShu[3][3]={};
  16. bool check;
  17.  
  18. for (arrEnt1D=0;arrEnt1D<3;arrEnt1D++){ // First dimension
  19. for (arrEnt2D=0;arrEnt2D<3;arrEnt2D++){ // Second dimension
  20. do {
  21. do {
  22. cout << "Enter 1-9: ";
  23. cin >> test;
  24. } while (test < 1 || test > 9); // Make sure it's in-between 1-9
  25. check = true; // Set bool so we can get out of loops
  26.  
  27. for (count=0;count<3;count++){ //Loop back into the array to see what's inside
  28. for (count1=0;count1<3;count1++) {
  29. if (test==loShu[count][count1]){ //If the current cin number is already inside, return to beginning
  30. cout << "Duplicate number, try again.\n"; //and get a different number
  31. check = false;
  32. }
  33. }
  34. }
  35. } while (!check);
  36. loShu[arrEnt1D][arrEnt2D] = test; //If number checks out, add it in
  37.  
  38.  
  39. }
  40. }
  41.  
  42. cout << "\n";
  43. for (displayR=0;displayR<3;displayR++){ // Display the matrix
  44. for (displayC=0;displayC<3;displayC++)
  45. cout << loShu[displayR][displayC] << " ";
  46. cout << "\n";
  47. }
  48.  
  49. if (loShu[0][0] + loShu [0][1] + loShu [0][2] == 15){ // If ALL rows horizontal, vertical, diagonal = 15
  50. if (loShu[1][0] + loShu [1][1] + loShu [1][2] == 15) { // Then it's a magic square, otherwise nope
  51. if (loShu[2][0] + loShu [2][1] + loShu [2][2] == 15) {
  52. if (loShu[0][0] + loShu [1][0] + loShu [2][0] == 15){
  53. if (loShu[0][1] + loShu [1][1] + loShu [2][1] == 15) {
  54. if (loShu[2][0] + loShu [2][1] + loShu [2][2] == 15) {
  55. if (loShu[0][0] + loShu [1][1] + loShu [2][2] == 15) {
  56. if (loShu[2][0] + loShu [1][1] + loShu [0][2] == 15)
  57. cout << "\nMagic square found!";
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. else
  66. cout << "\nNot a magic square :( " << endl;
  67.  
  68. return;
  69. }
  70.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: illegal character: '#'
#include <iostream>
^
Main.java:1: error: class, interface, or enum expected
#include <iostream>
         ^
Main.java:4: error: class, interface, or enum expected
void MagicBox();
^
Main.java:6: error: class, interface, or enum expected
int main () {
^
Main.java:10: error: class, interface, or enum expected
	return 0;
	^
Main.java:11: error: class, interface, or enum expected
}
^
Main.java:15: error: class, interface, or enum expected
	int arrEnt1D,arrEnt2D,test,count,count1,loShu[3][3]={};
	^
Main.java:16: error: class, interface, or enum expected
	bool check;
	^
Main.java:18: error: class, interface, or enum expected
	for (arrEnt1D=0;arrEnt1D<3;arrEnt1D++){				// First dimension
	^
Main.java:18: error: class, interface, or enum expected
	for (arrEnt1D=0;arrEnt1D<3;arrEnt1D++){				// First dimension
	                ^
Main.java:18: error: class, interface, or enum expected
	for (arrEnt1D=0;arrEnt1D<3;arrEnt1D++){				// First dimension
	                           ^
Main.java:19: error: class, interface, or enum expected
		for (arrEnt2D=0;arrEnt2D<3;arrEnt2D++){			// Second dimension
		                ^
Main.java:19: error: class, interface, or enum expected
		for (arrEnt2D=0;arrEnt2D<3;arrEnt2D++){			// Second dimension
		                           ^
Main.java:23: error: class, interface, or enum expected
					cin >> test;
					^
Main.java:24: error: class, interface, or enum expected
				} while (test < 1 || test > 9);		// Make sure it's in-between 1-9
				^
Main.java:25: error: class, interface, or enum expected
				check = true;							// Set bool so we can get out of loops
				^
Main.java:27: error: class, interface, or enum expected
				for (count=0;count<3;count++){							//Loop back into the array to see what's inside
				^
Main.java:27: error: class, interface, or enum expected
				for (count=0;count<3;count++){							//Loop back into the array to see what's inside
				             ^
Main.java:27: error: class, interface, or enum expected
				for (count=0;count<3;count++){							//Loop back into the array to see what's inside
				                     ^
Main.java:28: error: class, interface, or enum expected
					for (count1=0;count1<3;count1++) {
					              ^
Main.java:28: error: class, interface, or enum expected
					for (count1=0;count1<3;count1++) {
					                       ^
Main.java:31: error: class, interface, or enum expected
							check = false;
							^
Main.java:32: error: class, interface, or enum expected
						}
						^
Main.java:36: error: class, interface, or enum expected
			loShu[arrEnt1D][arrEnt2D] = test;							//If number checks out, add it in
			^
Main.java:39: error: class, interface, or enum expected
		}
		^
Main.java:43: error: class, interface, or enum expected
	for (displayR=0;displayR<3;displayR++){							// Display the matrix
	^
Main.java:43: error: class, interface, or enum expected
	for (displayR=0;displayR<3;displayR++){							// Display the matrix
	                ^
Main.java:43: error: class, interface, or enum expected
	for (displayR=0;displayR<3;displayR++){							// Display the matrix
	                           ^
Main.java:44: error: class, interface, or enum expected
		for (displayC=0;displayC<3;displayC++)
		                ^
Main.java:44: error: class, interface, or enum expected
		for (displayC=0;displayC<3;displayC++)
		                           ^
Main.java:46: error: class, interface, or enum expected
		cout << "\n";
		^
Main.java:47: error: class, interface, or enum expected
	}
	^
Main.java:58: error: class, interface, or enum expected
							}
							^
Main.java:68: error: class, interface, or enum expected
	return;
	^
Main.java:69: error: class, interface, or enum expected
}
^
35 errors
stdout
Standard output is empty