Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Questions

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
MegaForum
Grandmaster Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 558

PostPosted: Fri Jul 04, 2008 2:16 pm    Post subject: Questions Reply with quote

Hi guys, just got a few questions. Smile (Again?? I know sorry lol Confused)

Many you remember my number guess game. After a few suggestions and changes theres 1 problem and I have 1 question Razz.

Problem: The number that is randomy selected is ALWAYS 42. I'm not sure if the formula is messed up or if I changed something on accident.

Question: What kind of statement can I use to dissallow letters. Basically all I'm asking is an example of something that would make it so if someone typed in a letter,word, or a symbol that It would come up with a message of my choice so that only numbers are allowed. Thanks for the help once again. Very Happy.

Current Source:

Code:

#include "iostream.h"
#include "stdlib.h"
#include "ctime.h"
using namespace std;
int main()
{
   int number;
   int tries;
   int mynumber=rand()%100+1;
   
   cout << "You get 3 tries to match my number! 1-100"<< endl;   
   for(int tries=1; tries <=5; tries++)
   {
      cout << "Enter number"  << tries << endl;
      cin >> number;
      if(number == mynumber)
      {
         cout << "You got my number correct!" << endl;
         break;
      }
      else if(number != mynumber)
      {
         cout << "Your are incorrect. " << endl;
      }
      if(number > mynumber)
      {
         cout << "Your number is higher than the correct number, try again." << endl;
      }
      if(number < mynumber)
      {
         cout << "Your number is lower than the correct number, try again." << endl;
      }
   }
   system("PAUSE");
   return 0;
}


Note: For people who are curious why my headers all are .h or have " " symbols is because in visual C++ 2008, you have name your headers w/e.h and its kept seperate from the main source so you tell it to use that file by using " " but it's really the normal thing. Laughing
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Fri Jul 04, 2008 2:30 pm    Post subject: Reply with quote

Here's an example program that does the same thing, but 1-10.

Code:

/* rand example: guess the number */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main ()
{
  int iSecret, iGuess;

  /* initialize random seed: */
  srand ( time(NULL) );

  /* generate secret number: */
  iSecret = rand() % 10 + 1;

  do {
    printf ("Guess the number (1 to 10): ");
    scanf ("%d",&iGuess);
    if (iSecret<iGuess) puts ("The secret number is lower");
    else if (iSecret>iGuess) puts ("The secret number is higher");
  } while (iSecret!=iGuess);

  puts ("Congratulations!");
  return 0;
}

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25832
Location: The netherlands

PostPosted: Fri Jul 04, 2008 3:11 pm    Post subject: Reply with quote

the important difference: srand
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites