Hi!
Again things went wrong and when I was trying to write an IsMagic program,I faced an error.
at line
41 I get a break and error.
(I can't understand the reason)
Let me give an explanation about the program. This gets the numbers of a matrix from the user and adds up the rows and columns and
Xs
(I don't know what are they in English) and tells if they are the same or not, but when it is going to add up the numbers of a row it breaks.
(VS2010, Win32ConsoleApplication)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int a,**m,i,j,n1,n2;
bool magic=true;
cout<<"What is the length and width of your square?"<<endl;
cin>>a;
cout<<"Now enter these, which are wanted:"<<endl;
m=new int *[a];
for (i=0;i<a;i++)
m[i]=new int [a];
for (i=1;i<=a;i++)
{
for (j=1;j<=a;j++)
{
cout<<"M["<<i<<"]"<<"["<<j<<"] :";
cin>>n1;
m[i-1][j-1]=n1;
}
}
cout<<"\nThis is your Matrix:\n\n";
for (i=0;i<a;i++)
{
for (j=0;j<a;j++)
{
cout<<m[i][j]<<"\t";
}
cout<<endl<<endl;
}
cout<<"\nand it is ";
for (i=0;i<a;i++)
{
if (i>0)
n2=n1;
n1=0;
for(j=0;j<a;j++)
{
n1=n1+m[i][j];
}
if (i>0)
{
if (n2!=n1)
{
magic=false;
cout<<"not magic.";
break;
}
if (magic==false)
break;
}
if (magic==false)
break;
}
if (magic==true)
{
cout<<"magic.";
}
cin>>a;
cout<<"\nPress any key to continue ... ";
getch();
}
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
And I have another question:
is there some keyword like
endl , but takes the line one level upper? I mean the previous line, not next line???
Thank you in advance and Thanks for answering my earlier Topics.