Thread: Hi all, few questions

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    5

    Hi all, few questions

    Hi, I just started using c++ yesterday night, I was wondering if someone could help me with these questions:

    1) How do i make clickable text (button) and choose what it shows when ive clicked it?

    2) What type of program do i make it so i can send it to my friends and they can open it?

    3) How do i make a random number between 1 and 3?

    thanks in advance,
    yhack

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    1.) brush up on your winAPI programming if you want a windows type interface (with clickable buttons)

    2.) not sure what you are asking.. i'm thinking just send them the .exe executable file that you create when you compile your code

    3.) Here is an awesome FAQ on random numbers. It's pretty easy. Just don't forget to seed the random number generator (per the FAQ) once per run of the program.

    Code:
    cout << rand()%4   //will output a number between 0 and 3
    Last edited by The Brain; 10-03-2004 at 04:25 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    5
    thanks

    for question 1... instead of buttons can I have it so when u press the button it shows other stuff. (dont have to press enter)

  4. #4
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    I like to use the somewhat non-standard getch() function from the non-standard <conio.h> library.. simply put getch() where you want to read in a character without pressing enter.. here are a couple of examples:


    Code:
    char command;
    
    cout << "Press 1  to start";
    
    command = getch();
    or...

    Code:
    char get_user_command()
    {
    
    	    cout << "\n\n 'H' to HIT"
    		 << "\n 'S' to STAY"
    		 << "\n 'Q' to QUIT\n\n";
    	
    	return getch();	
    
    }
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    5
    sorry i dont understand this getch thing can you explain it to me?

  6. #6
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    all you have to remember.. is to place the getch() function.. whever you expect a user entry.. like in this example:

    Code:
    char command;
    
    cout << "Press 1  to start";
    
    command = getch();
    You place getch() where you expect a user entry.. the user will press "1" and will not have to hit the enter key and in this example... it will store the user entry into the 'command' variable.. which has been declared as a 'char' variable.. so it will contain the user entry... and you can make decisions in your program based on this user entry

    I think you should give it a try.. i think if you try it you'll catch on to how it works once you see it in use
    Last edited by The Brain; 10-03-2004 at 04:50 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  7. #7
    Registered User
    Join Date
    Oct 2004
    Posts
    5
    cool thanks!!!

    i think this will be the last question.

    on the exe file how do i make it have a picture instead of a picture of a window?

    thanks again

  8. #8
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    I think just as with any windows icon.. i think you can right click on the icon.. go to 'properties', and then I think there is an option to 'change icon'.. but i think by default there are a very few icons to chose from.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  9. #9
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    For your icon problem you can make a resource file check out www.winprog.org for details
    Woop?

  10. #10
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    getch() isn't perfect.. but it's quick and easy.. and included on a lot of compilers...

    also doesn't leave much in the way of exception handling.. but nothing that can't be handled w/ a little bit of extra code.
    Last edited by The Brain; 10-03-2004 at 05:12 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM