Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

(C++) Funny little number game

Newbie Spellweaver
Joined
May 3, 2008
Messages
83
Reaction score
0
Started c++ a week ago, and this is so far the biggest thing I've accomplished with it so far.

Ideas for helping me to improve are always accepted :)

Code:
#include <iostream>  
#include <ctime> 
#include <windows.h>


using namespace std;

int main () 
{
    keybd_event(VK_MENU,0x36,0,0);
    keybd_event(VK_RETURN,0x1c,0,0);
    keybd_event(VK_RETURN,0x1c,KEYEVENTF_KEYUP,0);
    keybd_event(VK_MENU,0x36,KEYEVENTF_KEYUP,0);

int age;
int rlage;
string p; 

cout << "Please enter your age: "; 
cin  >> age; 

if ( age < 40 ) { 
cout << "You are pretty young!\n\n"; 
}
else if ( age > 41 ) { 
cout << "You are getting old\n\n"; 
}
cin.get();


cout << "Wanna play guess the number!?!?! (y/n): ";
getline (cin, p);
if (p == "n") {
     return 0; }
     else {
system("CLS");
cout << "Ok!!!\n";
cout << "Loading.\n";
Sleep(500);
system("CLS");
cout << "Ok!!!\n";
cout << "Loading..\n";
Sleep(500);
system("CLS");
cout << "Ok!!!\n";
cout << "Loading...\n";
Sleep(500);
system("CLS");
cout << "Ok!!!\n";
cout << "Loading....\n";
Sleep(500);
system("CLS");
cout << "Ok!!!\n";
cout << "Loading.....\n";
Sleep(500);
system("CLS");
cout << "Ok!!!\n";
cout << "Loading.\n";
Sleep(500);
system("CLS");
cout << "Ok!!!\n";
cout << "Loading..\n";
Sleep(500);
system("CLS");
cout << "Ok!!!\n";
cout << "Loading...\n";
Sleep(500);
system("CLS");
cout << "Ok!!!\n";
cout << "Loading....\n";
Sleep(500);
system("CLS");
cout << "Ok!!!\n";
cout << "Loading.....\n";
Sleep(500);
}
system("CLS");
    srand((unsigned)time(0)); 
    int random_integer; 
    int lowest=1, highest=1000; 
    int range=(highest-lowest)+1; 
        random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0)); 
        rlage = random_integer;

cout << "Guess the number between 1 and 1000: ";
do
{

cin >> age;

if ( age <= rlage ) {
cout<<"Your cold, keep guessing\n";
}
else if ( age > rlage ) {
cout<<"Your going to high, keep guessing\n";
}
else if ( age == rlage ) {
cout<<"Well done! You guessed correctly\n";
}

} while (age != rlage);

return 0;

}
 
Supreme Arcanarch
Loyal Member
Joined
Mar 23, 2007
Messages
931
Reaction score
10
I bet those loadings would be annoying. =)

Otherwise, very good. C++ rocks.
 
Super Mexican
Loyal Member
Joined
Jun 26, 2008
Messages
1,517
Reaction score
2
Very nice. But maybe try not to use a system call for CLS.
I hear that its bad practice.

Otherewise very awesome!! ^^
Indeed C++ is teh best!

EDIT: When I guess correctly thew screen just dissapears.
You need to put a pause before the end of the game so you can see the end screen.
Hope I helped.
 
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
I've got a few points for you to improve on:

1. Try to make programs as fast as possible, that is, remove the loading part, lol, it annoys and is not needed.

Also, it seems system calls (system()), is rather slow...

2. Try, if you can, to make the code cross-platform (except if you're an MS freak :O). System() and Sleep() are not cross-platform (though for system() it depends...).

3. Use indentation, it helps a lot!

Otherwise, very good. C++ rocks.

I second that :D
 
Newbie Spellweaver
Joined
May 3, 2008
Messages
83
Reaction score
0
aye, I know system is not cross platform, all it does is call the string + .exe from within the system32 folder. If you guys know an alternative to CLS, sleep, and pause (apart from cin.get) please let me know! ^_^

P.S. The loading screens were just to test something lol
 
Back
Top