Click here to Skip to main content
15,937,066 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C++
#include<iostream.h>
#include<ctime.h>
#include<cstdlib.h>
#include<fstream.h>


using name space std;
double prob()
{
	 return(static_cast<double>(rand())/RAND_MAX);
}

int main()
{
	int size=15;double density;
	cout<<"graph size?"<<endl;
	cin>>size;
	cout<<"graph density (0,1)?"<<endl;
	cin>>density;
	bool**graph;
	int**color;
	int**cost;
	srand(time(0));     //seed random number generator
	graph=new bool*[size];
	color=new int*[size];
	cost=new int*[size];
	for(int i=0;i<size;>	{
		graph[i]=new bool[size];
		color[i]=new int[size];
		cost[i]=new int[size];
	}
	for(int i=0;i			for(int j=1;j<size;++j)>
				  if(i==j)graph[i][j]=false;  //no loops
				  else   graph[i][j]=graph[i][j]=(prob()<density);>

	for(int i=0;i			for(int j=1;j<size;++j)>
				 if(graph[i][j]){
					 color[i][j]=color[i][j]=rand()%3;
					 cost[i][j]=cost[j][i]=prob()*30;
			}
	ofstream  outp("graph_data.txt");
	outp<<size<<"\n";
	for(int i=0;i<size;++i)>
		 for(int j=0;j<size;++j){>
			  if(graph[i][j])
			  outp <<i<<'\t'<<j<<'\t'<<cost[i][j]<<'\t'<<color[i][j]<<'\t';
		 }


	return 0;

}


What I have tried:

I tried to compile it it has given declaration syntax errors.Error declarations.
Posted
Updated 22-Jul-16 5:58am
v2
Comments
E.F. Nijboer 22-Jul-16 11:51am    
Please edit the question and add some markup for your code. Also, add the the error message the compiler gives you and highlight the line where the error occurs.
Jochen Arndt 22-Jul-16 11:51am    
It would be helpful to know the exact error messages and on which lines they occured.
jeron1 22-Jul-16 12:32pm    
graph[i][j]=graph[i][j]=(prob()DENSITY);

color[i][j]=color[i][j]=rand()%3;

There's some redundancy here.
Philippe Mori 23-Jul-16 10:14am    
Please format your code correctly and put a single statement per line. As written, the code does not make sense (for example the incomplete for statement and the many > symbols).

1 solution

bug at this line (2 times in code):
C++
for(int i=0;i			for(int j=1;j<size;++j)>

Don't know what you intended to do with this:
C++
color[i][j]=color[i][j]=rand()%3;


You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900