Hello everyone. This is a relatively simple program that is driving me crazy. The user enters how many verticies and how many edges. The program then asks where the edges are...in a 2D array. If the user enters a 1 (indicated there is an edge) that array element is set to 1. For some reason my print out is all wrong. It prints out to many elements, and incorrect values.
Any help is appreciated, I think I'm just missing some minor thing....but I cannot find it.
Thanks,
J
Any help is appreciated, I think I'm just missing some minor thing....but I cannot find it.
Code:
#include <iostream>
using namespace std;
void main ()
{
int graph[10][10]={0,0}, num_vert=0, num_edge=0,r=0,c=0,cnt=0,i=0, j=0;
cout<<"Enter the number of verticies: "<<endl;
cin>>num_vert;
cout<<"Enter the number of edges: "<<endl;
cin>>num_edge;
for (i=0;i<num_edge;++i)
for (j=0;j<num_edge;++j)
{
cout<<"Is there an edge between "<<i<<" "<<j<<endl;
cin>>cnt;
if (cnt==1)
graph[i][j]=1;
else
graph[i][j]=0;
}
i=0;
for (i=0;i<num_vert;++i)
for (j=0;j<num_vert;++j)
cout<<"GRAPH "<<i<<" "<<j<<" "<<graph[i][j]<<endl;
i=0;
do
{
cout<<" "<<i; // top header
++i;
}
while(i<num_vert);
int t=0;
do //output
{
cout<<endl<<endl<<t<<"|";
for (int r=0;r<num_edge;++r)
for (int c=0;c<num_edge+1;++c)
cout<<" "<<graph[r][c];
++t;
}
while ( t<num_vert);
cout<<endl<<"T "<<t<<" NUM_VERT "<<num_vert<<" NUM_EDGE "<<num_edge;
}
J
Comment