473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

pls help debug my c++ program!!!

hi..

I am a newbee to c++ programming.. the program compiles.. but when i run, the command window prompt hangs.. and there is no output.. Pls help me out..

the source code is attached.. thanks in advance...



Expand|Select|Wrap|Line Numbers
  1. # include <iostream.h>
  2. # include <cstdlib>
  3.  
  4. using namespace std; 
  5.  
  6. // The types of components that can be present in the circuit.
  7. enum component_type {resistor,capacitor,inductor};
  8. typedef int node;
  9.  
  10. // population size for the GA and the declaration of the classes gene and chromosome.
  11. int popsize=100;
  12. int s[100];
  13.  
  14. class gene
  15. {
  16.       public:
  17.               component_type type;
  18.               node n1,n2;
  19. };
  20. class chromosome
  21. {
  22.       public:
  23.              gene genes[20];
  24.  
  25.              //population initialisation
  26.              void initialisation()
  27.              {          
  28.                   chromosome inipop[popsize];
  29.  
  30.                   for (int i=1;i<=popsize;i++)
  31.                   {   
  32.                       //randomisation of the number of genes and nodes
  33.                       int number_genes=(rand()%20)+1;
  34.                       int number_nodes=3;
  35.  
  36.                       for (int j=1;j<=number_genes;j++)
  37.                       {
  38.                           int comp=(rand() % 2) ; 
  39.                           inipop[i].genes[j].type=component_type(comp);
  40.                           inipop[i].genes[j].n1=(rand()%(number_nodes+1));
  41.                           inipop[i].genes[j].n2=(rand()%(number_nodes+1));
  42.                           while (inipop[i].genes[j].n2==inipop[i].genes[j].n1)
  43.                           {
  44.                                 inipop[i].genes[j].n2=(rand()%(number_nodes+1));
  45.                           }
  46.                           number_nodes++;
  47.                       }
  48.                       s[i]=number_genes;
  49.                   }
  50.                   for (int l=1;l<=popsize;l++)
  51.                       cout<<s[l];
  52.                   for (int i=1;i<=100;i++)
  53.                   {
  54.                       for (int j=1;j<s[i];j++)
  55.                       {
  56.                           cout<<inipop[i].genes[j].type<<"\t"<<inipop[i].genes[j].n1<<"\t"<<inipop[i].genes[j].n2<<"\n";
  57.                       }
  58.                   }
  59.            }
  60.  
  61.  
  62. }a1;
  63.  
  64. int main()
  65. {
  66.     a1.initialisation();
  67.     system("PAUSE");
  68.     return 0;
  69. }
Dec 28 '06 #1
3 1684
r035198x
13,262 8TB
hi..

I am a newbee to c++ programming.. the program compiles.. but when i run, the command window prompt hangs.. and there is no output.. Pls help me out..

the source code is attached.. thanks in advance...



Expand|Select|Wrap|Line Numbers
  1. # include <iostream.h>
  2. # include <cstdlib>
  3.  
  4. using namespace std; 
  5.  
  6. // The types of components that can be present in the circuit.
  7. enum component_type {resistor,capacitor,inductor};
  8. typedef int node;
  9.  
  10. // population size for the GA and the declaration of the classes gene and chromosome.
  11. int popsize=100;
  12. int s[100];
  13.  
  14. class gene
  15. {
  16.       public:
  17.               component_type type;
  18.               node n1,n2;
  19. };
  20. class chromosome
  21. {
  22.       public:
  23.              gene genes[20];
  24.  
  25.              //population initialisation
  26.              void initialisation()
  27.              {          
  28.                   chromosome inipop[popsize];
  29.  
  30.                   for (int i=1;i<=popsize;i++)
  31.                   {   
  32.                       //randomisation of the number of genes and nodes
  33.                       int number_genes=(rand()%20)+1;
  34.                       int number_nodes=3;
  35.  
  36.                       for (int j=1;j<=number_genes;j++)
  37.                       {
  38.                           int comp=(rand() % 2) ; 
  39.                           inipop[i].genes[j].type=component_type(comp);
  40.                           inipop[i].genes[j].n1=(rand()%(number_nodes+1));
  41.                           inipop[i].genes[j].n2=(rand()%(number_nodes+1));
  42.                           while (inipop[i].genes[j].n2==inipop[i].genes[j].n1)
  43.                           {
  44.                                 inipop[i].genes[j].n2=(rand()%(number_nodes+1));
  45.                           }
  46.                           number_nodes++;
  47.                       }
  48.                       s[i]=number_genes;
  49.                   }
  50.                   for (int l=1;l<=popsize;l++)
  51.                       cout<<s[l];
  52.                   for (int i=1;i<=100;i++)
  53.                   {
  54.                       for (int j=1;j<s[i];j++)
  55.                       {
  56.                           cout<<inipop[i].genes[j].type<<"\t"<<inipop[i].genes[j].n1<<"\t"<<inipop[i].genes[j].n2<<"\n";
  57.                       }
  58.                   }
  59.            }
  60.  
  61.  
  62. }a1;
  63.  
  64. int main()
  65. {
  66.     a1.initialisation();
  67.     system("PAUSE");
  68.     return 0;
  69. }
try putting some output in the while loop to see how many times it's iterating

Expand|Select|Wrap|Line Numbers
  1. while (inipop[i].genes[j].n2==inipop[i].genes[j].n1)
  2.     {
  3.       inipop[i].genes[j].n2=(rand()%(number_nodes+1));
  4.      cout<<"Something"<<endl;
  5.  }
Dec 28 '06 #2
hey..

i tried even commenting the while loop.. but the problem still exists.. :(
Dec 28 '06 #3
r035198x
13,262 8TB
hey..

i tried even commenting the while loop.. but the problem still exists.. :(
Debug it with cout statements. If you put a cout as the first statement of main is it outputting something?
Dec 28 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mahmood Ahmad | last post by:
Hello, I have written a program that reads three types of records, validates them acording to certain requirements and writes the valid records into a binary file. The invalid records are...
1
by: VM | last post by:
How can I debug an application during execution? I'm trying to find a way to look at the contents of a variable through the Debug window (like in VB6). Thanks.
0
by: Jeff | last post by:
I am writing a program that must be run on a specific server due to its dependancy on the application we are writing for. VS .NET is installed on my laptop and I installed the Remote Debugging...
2
by: Smoke | last post by:
Whats is the deal with Debug.WriteLine command... I mean, in my programs, i usually add many of those commands to debug it while programming, and to be able to find bugs and things easier, but, it...
2
by: FBM | last post by:
Hi, I am preparing project for submission and i'd like to allow the print out of debug messages. I know that with something like #define DEBUG #ifdef DEBUG print(X); #endif
1
by: apacheutara | last post by:
hai.. i juz started learning C++ language & started to try creating a program. its a simple contacts list. here's the code: ========================================================= ...
3
by: BobAchgill | last post by:
I downloaded and tried to install my program on a Hebrew Windows Professional computer and got the error at start up of the program: Application has generated an exception that could not be...
6
by: Scubadude | last post by:
Hi, I'm new to perl and have run into some roadblocks while trying to run tutorials. I have installed Apache v2.2.3 I have installed ActivePerl v6.6.1.638 I have installed php v5.2.0 I am...
3
momotaro
by: momotaro | last post by:
am supposed to have the same data that i have entred but its not the case!!! can you help me???? #include<stdio.h> typedef struct { char name; double salary; int rank;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.