Hi All,

I'm having a bit of trouble with a simulation I am writing in C++. Any help to solve the problem would be appreciated.

The simuation needs to run 5500000000 times.

When it gets to 2100000000, the counter I am using changes to -210000000. So as you can see, it will never finsh and do what I want.

I presume this is to do with how I have declared the variables, but am unsure of how to solve this.

Selected code below

int clock = 0;

// Start the simulation
  while(clock < simulationlength)
    //arrival process on the corporate links
    if (clock % 4 == 0) 

Hope you can help.


use unsigned long intead of int. But first check for the maximum value for your compiler in the file limits.h. The maximum value for an unsigned long on my compiler is 4,294,967,295 -- slightly smaller than the value you want. You may have to go with a 64-bit integer, longlong on some compilers and __int64 on others.

Yeah, integers wrap around themselves. For example if you had a signed (takes positive and negative numbers, i think the min is -32,000 something and max is 32,000 something), then when you get to that maximum number and add 1 it will wrap around and start from its min.

If you have an unsigned variable (only positives), the maximum number it can take is double the normal. If you use unsigned long int, you will be able to use upto a value in the millions

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.