# Thread: Negative Numbers

1. ## Negative Numbers

Im writing a program that generates random number's from a certain point, my program works allright if the user enters a positive number but if the user enters a negative number if starts from the wrong point ( the number is changed into a positive one) what should i do?

Code:
LRESULT CALLBACK ProbeProc(HWND hwnd,UINT message,WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
case WM_CLOSE:
EndDialog(hwnd,false);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
MessageBox(NULL," AutoProbe 1.0 Copyright 2004\n Rebel Collective.\n Version Imformation : 1.0","About AutoProbe 1.0",MB_OKCANCEL);
break;
case IDOK:
int amountGen = 0;
amountGen = GetDlgItemInt(hwnd,IDC_EDIT1,NULL,NULL);

if (amountGen <= 0)  // check to see if the number of cords to generate is above 0
// if it isent give the user a warning
{
MessageBox(NULL,"Please enter a number above 0","Runtime Error",MB_OKCANCEL);
}
else
{
int xCord,yCord,zCord;

xCord = GetDlgItemInt(hwnd,IDC_EDIT3,NULL,NULL);
yCord = GetDlgItemInt(hwnd,IDC_EDIT4,NULL,NULL);
zCord = GetDlgItemInt(hwnd,IDC_EDIT5,NULL,NULL);

for (int i=0; i<amountGen; i++)
{
int temxCord = xCord;
int temyCord = yCord;
int temzCord = zCord;

ofstream FILE("Data.txt", ios::app);

temxCord = temxCord + 100;

FILE << temxCord <<" " << temyCord <<" "<< temzCord <<endl;

temxCord = xCord;
temyCord = temyCord + 100;

FILE << temxCord <<" "<< temyCord <<" "<< temzCord <<endl;

temyCord = yCord;
temzCord = temzCord + 100;

FILE << temxCord <<" "<< temyCord <<" "<< temzCord <<endl;

temzCord = zCord;

xCord = xCord + 100;
yCord = yCord + 100;
zCord = zCord + 100;
}
}
break;  // IDOK
}
break;
}
return false;
}

2. 1) You aren't even using any randomizing functions like rand()...
2) You shouldn't be using FILE as a variable name since it might make confusion with FILE in cstdio.

3. > amountGen = GetDlgItemInt(hwnd,IDC_EDIT1,NULL,NULL);
amountGen = GetDlgItemInt(hwnd,IDC_EDIT1,NULL,TRUE);

4. Thanks so much swoopy how did that make it work? also ive found another bug if the user wants to generate a large amount of cords it realy lags would there be any way to speed generation up?

5. >Thanks so much swoopy how did that make it work?
That what the reference says.
http://msdn.microsoft.com/library/de...dlgitemint.asp

>also ive found another bug if the user wants to generate a large amount of cords it realy lags would there be any way to speed generation up?

The only thing I can think of is to open the file only once (outside the dialog proc), and make the ofstream global:
Code:
ofstream FILE("Data.txt", ios::app);
I don't know if this will speed it up.

Popular pages Recent additions