Thread: srand()

  1. #16
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Well I guess I should elaborate on what I am going to do so maybe you guys can help me out since I am stuck with my head up my ass on this one....
    What I need to do
    (This is not for homework, but rather a raffle going on at http://forums.techpowerup.com/showthread.php?t=15937 for our moderator Dark_Ride)
    Anyways I want to
    Type in the person who bought tickets and then the amount of tickets
    have that write to an ini file
    Assign a specific number for each ticket, to help it being random
    loop that until everyone has been entered in
    sum up amount of tickets to put in to srand() function
    pick the random number
    compare it to the peope in the ini file
    see who has the ticket that matches up with that number
    and that's about it... if theres any way that I can make that file not editable by anyone except through the program that will be great.
    Maybe encrypt the file?

  2. #17
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>So how would I make it choose between 1-100?<<

    faq.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #18
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Or better yet, Prelude's article: http://eternallyconfuzzled.com/articles/rand.html
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #19
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    If you haven't read my post above Ken then I perfer you do so as I am asking for help with more than the srand() function.

  5. #20
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    GAH
    Alright I have to write it to be a GUI >.<
    Sooo
    The GUI window will be
    +---------------------------------------------------------------------------+
    | |
    | *Title* |
    | |
    | |ListboxTypeName| |Type num of tickets| |Submit button| |
    | |List all people and number of tickets| |
    | |
    | |Display winner and ticket number| |
    | |
    +---------------------------------------------------------------------------+

  6. #21
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Quote Originally Posted by bikr692002
    GAH
    Alright I have to write it to be a GUI >.<
    Sooo
    The GUI window will be
    +---------------------------------------------------------------------------+
    | |
    | *Title* |
    | |
    | |ListboxTypeName| |Type num of tickets| |Submit button| |
    | |List all people and number of tickets| |
    | |
    | |Display winner and ticket number| |
    | |
    +---------------------------------------------------------------------------+
    Code tags preserve formatting . . .
    Code:
    +---------------------------------------------------------------------------+
    |                                                                           |
    |           *Title*                                                         |
    |                                                                           |
    |    |ListboxTypeName| |Type num of tickets| |Submit button|                |
    |     |List all people and number of tickets|                               |
    |                                                                           |
    |        |Display winner and ticket number|                                 |
    |                                                                           |
    +---------------------------------------------------------------------------+
    Have you done any GUI programming before?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #22
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    I was answering to dwks, sorry.

    Anyways yeah I have done GUI programming before *cringes*....
    Wasn't that easy and it took me like a week just to get the program working.... and bugging out at that =\
    And I did a good amount of the code but a person here kept giving me the actuall entire code instead of helping me learn, which I appreciated alot and implimented but I didn't really learn anything which brings me back to here.... Anyways, I can't find the MSDN page that has to do with C++ comboboxes and listboxes and such. Does anyone have a link?

  8. #23
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #24
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Code:
    #include <windows.h>
    HINSTANCE g_hInst;
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
    					LPSTR lpCmdLine,int nCmdShow)
    {
    	MSG Msg;
    	HWND hwnd;
    	WNDCLASSEX wincl;
    	g_hInst=hInstance;
    	TCHAR chClassName[]=TEXT("TheThing");
    
    	wincl.cbClsExtra=0;
    	wincl.cbWndExtra=0;
    	wincl.style=CS_HREDRAW|CS_VREDRAW;
    	wincl.lpszMenuName=NULL;
    	wincl.hInstance=hInstance;
    	wincl.lpszClassName=chClassName;
    	wincl.cbSize=sizeof(WNDCLASSEX);
    	wincl.lpfnWndProc=(WNDPROC)WndProc;
    	wincl.hCursor=LoadCursor(NULL,IDC_ARROW);
    	wincl.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    	wincl.hIconSm=LoadIcon(NULL,IDI_APPLICATION);
    	wincl.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
    
    	if(!RegisterClassEx(&wincl))
    	{
    		MessageBox(0,"Window Registration Failed!","Error!",MB_ICONSTOP|MB_OK);
    		return 0;
    	}
    	hwnd=CreateWindowEx(0,chClassName,"TheThing",WS_OVERLAPPEDWINDOW,
    						CW_USEDEFAULT,CW_USEDEFAULT,660,480,HWND_DESKTOP,NULL,
    						hInstance,NULL);
    	if(hwnd==NULL)
    	{
    		MessageBox(0,"Window Creation Failed!","Error",MB_ICONSTOP|MB_OK);
    		return 0;
    	}
    	ShowWindow(hwnd,nCmdShow);
    	UpdateWindow(hwnd);
    	while(GetMessage(&Msg,NULL,0,0))
    	{
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);
    	}
    	return Msg.wParam;
    }
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    	HDC hdc;
    	PAINTSTRUCT ps;
    	TCHAR chTxt[32];
    	HWND hButton,hCombo,hCombo2;
    	LPSTR Greeting,Question,Option;
    	Option="Person";
    	Greeting="Well here it is, thanks for putting me through hell";
    	Question="Add person and number of tickets";
    
    	switch(msg)
    	{
    		case WM_CREATE:
    			hCombo=CreateWindowEx(NULL,"COMBOBOX","People",
    				WS_CHILD|WS_VISIBLE|CB_ADDSTRING,
    				120,240,180,100,hwnd,(HMENU)ID_COMBOBOX1,g_hInst,NULL);
    			hCombo2=CreateWindowEx(NULL,"COMBOBOX","People",
    				WS_CHILD|WS_VISIBLE|CB_ADDSTRING,
    				120,260,80,70,hwnd,(HMENU)ID_COMBOBOX2,g_hInst,NULL);
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"1");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"2");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"3");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"4");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"5");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"6");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"7");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"8");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"9");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"10");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"11");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"12");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"13");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"14");
    					SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    					lstrcpy(chTxt,"15");
    			hButton=CreateWindowEx(NULL,"Button","Submit",
    				WS_BORDER|WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
    				500,240,65,25,hwnd,NULL,g_hInst,NULL);
    			break;
    		case WM_PAINT:
    			hdc=BeginPaint(hwnd,&ps);
    			TextOut(hdc,160,40,Greeting,strlen(Greeting));
    			TextOut(hdc,196,160,Question,strlen(Question));
    			TextOut(hdc,20,240,Option,strlen(Option));
    			EndPaint(hwnd,&ps);
    			break;
    		case WM_CLOSE:
    			DestroyWindow(hwnd);
    			break;
    		case WM_DESTROY:
    			PostQuitMessage (0);
    			break;
    		default:
    			return DefWindowProc(hwnd,msg,wParam,lParam);
    	}
    	return 0;
    }
    But it won't compile
    for (HWND) ID_COMBOBOX1 and (HWND) ID_COMBOBOX2 its sayign its undefined

    Oh yeah and how do I let people type things in to the box?
    Last edited by bikr692002; 09-01-2006 at 06:05 PM.

  10. #25
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    . . . how do I let people type things in to the box?
    With a textbox?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  11. #26
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    Yeah but how do I make one?
    What class do I use besides "COMBOBOX" for the second argument in CreateWindowEx()

  12. #27
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I have no idea. I've never programmed GUI programs with C++.

    You might want to see if you can glean any information from this page, though: http://msdn.microsoft.com/library/de...ClassTopic.asp
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  13. #28
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    That is using the .net framework and I don't want to be implimenting that in such a small project right now

  14. #29
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    But it won't compile
    for (HWND) ID_COMBOBOX1 and (HWND) ID_COMBOBOX2 its sayign its undefined
    Yes. Because they're... undefined. Try... defining... them. Seriously. You should probably have a header with #define ID_COMBOBOX2 (somenumberhere).
    WS_CHILD|WS_VISIBLE|CB_ADDSTRING
    That isn't a valid style for a combobox. CB_ADDSTRING is a message that you can pass to a combobox, but not a style.
    Code:
    SendMessage(hCombo2,CB_ADDSTRING,0,(LPARAM)chTxt);
    lstrcpy(chTxt,"1");
    You might want to store the string to the variable before telling the combobox to add that string. Since you don't bother to initialize your variables, Bad Things(TM) could happen.
    However, since all your strings are constant, you can just say:
    Code:
    SendMessage(hCombo2, CB_ADDSTRING, 0, (LPARAM) "My string");
    Or, since you're adding numbers that are consecutive, why not make a loop?
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  15. #30
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    What do you mean the CB_ADDSTRING doesn't work?
    guess I'll use CBS_HASSTRINGS then
    Code:
    Check new post
    that is what I have so far. If you guys can tell me why it messes up when it inputs the UserName and NumOfTickets it would be greatly appreciated
    Last edited by bikr692002; 09-02-2006 at 07:33 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Use srand() twice in a function?
    By Jake.c in forum C Programming
    Replies: 5
    Last Post: 01-21-2009, 12:51 PM
  2. srand() in .Net
    By Sad Programmer in forum C++ Programming
    Replies: 6
    Last Post: 07-28-2003, 05:01 PM
  3. Same seed for srand yields different results
    By codegirl in forum C++ Programming
    Replies: 3
    Last Post: 06-23-2003, 02:39 PM
  4. When to srand()?
    By Imperito in forum C++ Programming
    Replies: 1
    Last Post: 05-12-2002, 12:20 AM
  5. srand()... possible reasons for failure
    By lightatdawn in forum C++ Programming
    Replies: 3
    Last Post: 12-18-2001, 02:33 AM