Thread: Negative Numbers

  1. #1
    Banned
    Join Date
    Oct 2004
    Posts
    250

    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. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    53
    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. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    > amountGen = GetDlgItemInt(hwnd,IDC_EDIT1,NULL,NULL);
    Try instead:
    amountGen = GetDlgItemInt(hwnd,IDC_EDIT1,NULL,TRUE);

  4. #4
    Banned
    Join Date
    Oct 2004
    Posts
    250
    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. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >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 subscribe to a feed

Similar Threads

  1. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 09:15 PM
  2. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  3. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  4. Line Numbers in VI and/or Visual C++ :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 02-10-2002, 10:54 PM
  5. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM