Skip to main content
GameDev.net gamedev.net
🔒 Locked

Wierd Number Outputs?

Started by Reggi Nov 27, 2009 at 11:59 AM 4 replies 1.1k views
Original Post
Reggi
Reggi
For the past 2 hours I've been trying to figure out why my program is returning incorrect outputs. I changed all of my integer variables into unsigned integers after realizing some of the numbers I'm working with are out of the integer range. But even after fixing that, 32 numbers out of the 1024 are coming out incorrectly.

#include <iostream>
#include <string>
#include <vector>



using namespace std;

void setD10Numbers(unsigned int* const d10Numbers,unsigned int* const d5NUMBERS);

int main()
{
	unsigned int d5NUMBERS[32] =        {11111,
										 11112,11121,11211,12111,21111,
								  		 11122,11212,12112,21112,11221,12121,21121,12211,21211,22111,
									 	 22211,22121,21221,12221,22112,21212,12212,21122,12122,11222,
										 12222,21222,22122,22212,22221,
									     22222};
	
	vector< vector<string> > genotype(1024); //declaring genotypes.
	
	for (int i = 0; i < 1024; ++i)
	{
		genotype.resize(1024);
	}

	(genotype[1023])[542] = "5421";
	cout << (genotype[1023])[542];

	unsigned int d10Numbers[1024];
	d10Numbers[1023] = 0;      // for use in setParent function

	setD10Numbers(d10Numbers,d5NUMBERS);
	
	unsigned int x = 0;

	while(x < 1024)        // testing to see if the function worked
	{
		cout << d10Numbers[x];
		cout << ",";
		cout << x;
		cout << ",";
		x++;
	}

	return 0;
}

void setD10Numbers(unsigned int* const d10Numbers,unsigned int* const d5NUMBERS)
{
	int x,i,c;
	x = i = c = 0;
	while(d10Numbers[1023] == 0)
	{	
		d10Numbers[c] = (d5NUMBERS[x] * 100000) + d5NUMBERS;
		c++;
		i++;

		if(i==31)
		{
			x++;
			i = 0;
		}
	}
}

variables d10Numbers[0] ~ d10Numbers[990] come out fine. 991~1023 come out with values in the upper range of the unsigned int.
Reggi
Reggi
ah, you can ignore that part. It's part of the program I was planning to create. I stopped to test why the program is not working correctly.
AHashem
AHashem
In setD10Numbers(), your if statement should be
if (i == 32) // not if (i==31)


HTH,

Atef Hashem
Reggi
Reggi
thanks a lot :O!
Reggi
Reggi
Sorry to post again so soon, but I've run into another problem. This time, I'm getting errors while trying to add characters and putting them into a string.

while(x<1024)	{		counter[0] = d10Numbers[x]/1000000000;		counter[1] = (d10Numbers[x]-(counter[0] * 1000000000))/100000000;		counter[2] = (d10Numbers[x]-(counter[0] * 1000000000)-(counter[1]*100000000))/10000000;		counter[3] = (d10Numbers[x]-(counter[0] * 1000000000)-(counter[1]*100000000)-(counter[2]*10000000))/1000000;		counter[4] = (d10Numbers[x]-(counter[0] * 1000000000)-(counter[1]*100000000)-(counter[2]*10000000)-(counter[3]*1000000))/100000;		counter[5] = (d10Numbers[x]-(counter[0] * 1000000000)-(counter[1]*100000000)-(counter[2]*10000000)-(counter[3]*1000000)-(counter[4]*100000))/10000;		counter[6] = (d10Numbers[x]-(counter[0] * 1000000000)-(counter[1]*100000000)-(counter[2]*10000000)-(counter[3]*1000000)-(counter[4]*100000)-(counter[5]*10000))/1000;		counter[7] = (d10Numbers[x]-(counter[0] * 1000000000)-(counter[1]*100000000)-(counter[2]*10000000)-(counter[3]*1000000)-(counter[4]*100000)-(counter[5]*10000)-(counter[6]*1000))/100;		counter[8] = (d10Numbers[x]-(counter[0] * 1000000000)-(counter[1]*100000000)-(counter[2]*10000000)-(counter[3]*1000000)-(counter[4]*100000)-(counter[5]*10000)-(counter[6]*1000)-(counter[7]*100))/10;		counter[9] = (d10Numbers[x]-(counter[0] * 1000000000)-(counter[1]*100000000)-(counter[2]*10000000)-(counter[3]*1000000)-(counter[4]*100000)-(counter[5]*10000)-(counter[6]*1000)-(counter[7]*100)-(counter[8]*10))/1;		        top[x]=                  original[counter[0]-1]  +                                 original[counter[1]+1]  +							     original[counter[2]+3]  +								 original[counter[3]+5]  +                                 original[counter[4]+7]  +								 original[counter[5]+9]  +									 original[counter[6]+11] +				                 original[counter[7]+13] +                                 original[counter[8]+15] +                                 original[counter[9]+17];				x++;	}


top is an array of strings. So top[x] is a string. original[counter[0]-1] and ect are characters. "original" is a string with "AaBbCcDdEeFfGgHhIiJj". The program compiles fine but when i try to output any string in "top" I get very odd symbols that occasionally change.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.