-
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 :)
-
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
-
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)
-
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();
}
-
sorry i dont understand this getch thing can you explain it to me?
-
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 :)
-
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
-
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.
-
For your icon problem you can make a resource file check out www.winprog.org for details :)
-
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.