I wrote this program and it compiles fine with Visual Studio. Problem is my teacher wants it compiled with g++ and I cant get it to compile. It says, "Main must return 'int'" Heres the entire program. I would appreciate any help/suggestions anyone can provide.
Code:
// '***' Represents start of new 'sub-function'
// <<Got rid of header files and conio>>
#include <iomanip>
#include <iostream>
using std::cout;
using std::cin;
using std::setw;
//max int of 15.
const unsigned x = 15;
//define matrix as x+1 by x+1.
typedef unsigned MatrixType[x+1][x+1];
//declare y as user defined dimension size (odd numbers only)
unsigned Y;
MatrixType Matrix;
//"sub-function" definitions.
void Description();
void Dimensions();
void Generate();
void Print();
void Exit();
//MAIN FUNCTION--include "sub-functions" in main function.
void main()
{
Description();
Dimensions();
Generate();
Print();
Exit();
}
//***Information screen using cout statements.
void Description()
{
cout<<"????????????????????????????????????????????????????????????????????????????\n";
cout<<"? ?\n";
cout<<"? MAGIC SQUARE PROGRAM ?\n";
cout<<"? ?\n";
cout<<"? ?\n";
cout<<"? This is a program that creates a magic square that ?\n";
cout<<"? will be filled in by you. A magic square is an x by x matrix ?\n";
cout<<"? that is filled with numbers so that the rows, columns and ?\n";
cout<<"? diagnol lines add up to be the same number. ?\n";
cout<<"? ?\n";
cout<<"? ?\n";
cout<<"????????????????????????????????????????????????????????????????????????????\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
cout<<"\n";
}
//***function for getting the dimensions from keyboard.
void Dimensions()
{
cout<<"Get ready to make your Magic Square!\n";
cout<<"Please enter an ODD number (3 through 15).\n";
cout<<"After that hit Enter.\n\n\n\n";
cin>> Y;
}
//***function for generating magic square with user defined input.
void Generate()
{
unsigned i;
unsigned Dsquare;
unsigned Row;
unsigned Column;
//arrange matrix so that Magic Square will work.
Row = 1;
Column = (Y+1)/2;
Matrix[Row][Column] = 1;
Dsquare = Y*Y;
for (i=2; i<=Dsquare; i++)
{
if ((i-1)%Y==0)
Row++;
else
{
Row--;
Column++;
if (Row==0)
Row = Y;
else if (Column==(Y+1))
Column = 1;
}
Matrix[Row][Column] = i;
}
}
//***function for printing results.
void Print()
{
unsigned Row;
unsigned Column;
//creating lined box around numbers.
cout<<"\n\n\n\n\n\n\n\n"<<setw((4*Y-10)/2)
<<""<<setw(2)
<<Y<<" x "
<<setw(2)<<Y<<" Square\n";
cout<<"ÚÄ";
//Creates top of box (margin spacing).
for (Column=1; Column<=Y; Column++)
cout<<"ÄÄÄÄ";
cout<<"¿\n";
for (Row=1; Row<=Y; Row++)
{
//Creates 'sides' of box.
cout<<"³ ";
for (Column=1; Column<=Y; Column++)
cout<<setw(3)<<Matrix[Row][Column]<<" ";
cout<<"³\n";
}
cout<<"ÀÄ";
//Creates bottom of box (margin spacing).
for (Column=1; Column<=Y; Column++)
cout<<"ÄÄÄÄ";
cout<<"Ù\n";
}
//***function for exit screen.
void Exit()
{
cout<<"This is a Magic Square!!!\n";
cout<<"\nThank you for using this program...\n";
cout<<"Please press any key to exit!\n\n\n\n";
}