Hello. I am challeging myself in one intresting task: I need to find out if there could be a way from one Vertex to another in Incidence matrix. So I arranged that matrix should be 4*4 and elements are going to be input by user. Bellow my test code which is doing something mystical in real life. Smbdy can you help me and tell where I am wrong and how to make this code working? I will really appreciate any advice. PS sorry for my engrish ^^
well the numeration indeed changed but the main thing about working not. after this change my program is not going longer y input. It just stops after this. Whats wrong then? http://clip2net.com/s/3sRDlZJ
Line 30 is the break instruction, this will quit out of the for loop regardless of the value of the variable. You can remove it as I can't see it's point in being there.
Oops, reformatted your code with indentation to make it a bit clearer. The break is probably ok, but your if statements need to use == rather than =.
#include<iostream>
int main()
{usingnamespace std;
int M[4][4];
int i, j;
cout<<"Fullfill the massiv: "<<'\n';
for(i=0; i<=3; i++)
{
for(j=0; j<=3; j++)
{
cout<<"M["<<i<<"]["<<j<<"] = ";
cin>>M[i][j];
}
}
cout<<"enter x"<<'\n';
cin>>i;
cout<<"enter y"<<'\n';
int y;
int n = 0;
cin>>y;
if(i==y)
cout<<"u are win";
elsefor(j=0; j<=3; j++) {
n++;
if(n==5)
cout<<"looser";
else {
if(M[i][j]==1)
{
if(i==y)
cout<<"win"<<'\n';
else
{
if(i==3)
i = 0;
else
i++;
}
}
elsebreak;
}
}
return (0);
}
.
Something wrong with it anyway :D
Here is a pic of algorithm which I used http://clip2net.com/clip/m0/7f34f-clip-35kb.jpg?nocache=1. The magic is that algorithm works and the code is not. I guess I am wrong in using cycles. Please advice!
Your loops still go from 1 to 4 instead of 0 to 3.
Here is a pic of algorithm which I used
When I click on that link it says that the picture has been archived. Can you provide another? It's hard to know what's wrong with the code when we can't tell how it's supposed to work.
It's hard for me to say what the problem is. I don't understand how the algorithm you showed is supposed to work, so it's hard to say if there's a problem with the code or the algorithm itself.