PDA

View Full Version : سوال: کمک در مورد ارور



Spate
سه شنبه 10 بهمن 1391, 11:13 صبح
سلام دوستان
کد زیر در هنگام کامپایل ارور میده!
لطفاَ راهنمایی کنید.
ممنون
#include<iostream.h>
#include<conio.h>

#define MAX 10

int *Vcolor,n,m;
int w[MAX][MAX]={0};

bool promising(int);

void m_coloring(int i)
{
int color;
if(promising(i))
if(i==n)
{
for(int index=1;index<=n;index++)
cout<<Vcolor[index]<<" ";
cout<<endl;
}
else
for(color=1;color<=m;color++)
{
Vcolor[i+1]=color;
m_coloring(i+1);
}
}

bool promising(int i)
{
int k;
bool myswitch;
k=1;
myswitch = true;
while (k<i && myswitch)
{
if(w[i][k] && Vcolor[i]==Vcolor[k])
myswitch = false;
k++;
}
return myswitch;
}

void main()
{
cout<<"Enter Number Of Vertices:\n";
cin>>n;
cout<<"Enter Number Of Color (m):\n";
cin>>m;
Vcolor=new int[m+1];
cout<<"Enter Your Graph Using Weight Matrix 1 If Exciting Edge And Else 0\n";
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if((i!=j)&&(i<j))
{
cout<<i<<" and "<<j<<" : ";
cin>>w[i][j];
w[j][i]=w[i][j];
}
if(i==j)
w[i][j]=0;
}
cout<<"\nOutput\n\n";
m_coloring(0);
cout<<"\nPress Any Key...\n";
getch();
}

hadi0x7c7
سه شنبه 10 بهمن 1391, 11:41 صبح
من اینو توی VC++2010 بدون مشکل کامپایل کردم:
#include<iostream>
#include<conio.h>
using namespace std;
#define MAX 10

int *Vcolor,n,m;
int w[MAX][MAX]={0};

bool promising(int);

void m_coloring(int i)
{
int color;
if(promising(i))
if(i==n)
{
for(int index=1;index<=n;index++)
cout<<Vcolor[index]<<" ";
cout<<endl;
}
else
for(color=1;color<=m;color++)
{
Vcolor[i+1]=color;
m_coloring(i+1);
}
}

bool promising(int i)
{
int k;
bool myswitch;
k=1;
myswitch = true;
while (k<i && myswitch)
{
if(w[i][k] && Vcolor[i]==Vcolor[k])
myswitch = false;
k++;
}
return myswitch;
}

void main()
{
cout<<"Enter Number Of Vertices:\n";
cin>>n;
cout<<"Enter Number Of Color (m):\n";
cin>>m;
Vcolor=new int[m+1];
cout<<"Enter Your Graph Using Weight Matrix 1 If Exciting Edge And Else 0\n";
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if((i!=j)&&(i<j))
{
cout<<i<<" and "<<j<<" : ";
cin>>w[i][j];
w[j][i]=w[i][j];
}
if(i==j)
w[i][j]=0;
}
cout<<"\nOutput\n\n";
m_coloring(0);
cout<<"\nPress Any Key...\n";
getch();
}

alij30
چهارشنبه 11 بهمن 1391, 20:55 عصر
منم اینو توی mingw با تغییر void به int در بدنه بون مشکل کامپایل کردم

sr2m72
چهارشنبه 11 بهمن 1391, 23:57 عصر
سلام
با Dev-C++ بدون مشكل كامپايل شد.
از چه كامپايلري استفاده ميكنيد؟

smemamian
پنج شنبه 12 بهمن 1391, 00:48 صبح
از هدرconio.h استفاده نکنید :


#include<iostream>
using namespace std;
#define MAX 10

int *Vcolor,n,m;
int w[MAX][MAX]={0};

bool promising(int);

void m_coloring(int i)
{
int color;
if(promising(i))
if(i==n)
{
for(int index=1;index<=n;index++)
cout<<Vcolor[index]<<" ";
cout<<endl;
}
else
for(color=1;color<=m;color++)
{
Vcolor[i+1]=color;
m_coloring(i+1);
}
}

bool promising(int i)
{
int k;
bool myswitch;
k=1;
myswitch = true;
while (k<i && myswitch)
{
if(w[i][k] && Vcolor[i]==Vcolor[k])
myswitch = false;
k++;
}
return myswitch;
}

int main()
{
cout<<"Enter Number Of Vertices:\n";
cin>>n;
cout<<"Enter Number Of Color (m):\n";
cin>>m;
Vcolor=new int[m+1];
cout<<"Enter Your Graph Using Weight Matrix 1 If Exciting Edge And Else 0\n";
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
if((i!=j)&&(i<j))
{
cout<<i<<" and "<<j<<" : ";
cin>>w[i][j];
w[j][i]=w[i][j];
}
if(i==j)
w[i][j]=0;
}
cout<<"\nOutput\n\n";
m_coloring(0);
cout<<"\nPress Any Key...\n";
cin.get();
return 0 ;
}