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 


[Help]C++ Loops
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Jul 03, 2008 4:55 pm    Post subject: Reply with quote

noz3001 wrote:
windows.h is bigger and is OS dependant.


Headers, no matter how big, do not make an impact on the final size of the PE image because they are used for function and type definitions - something for the compiler. If they are used for holding functions that need compiled you are using them wrong.

Also, chances are that if you are coming to this section to learn how to program, you are doing it in a Windows environment.

If all you are trying to accomplish is attempting to contradict me, please stop, you are wasting your time.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Thu Jul 03, 2008 5:08 pm    Post subject: Reply with quote

Flyte wrote:
noz3001 wrote:
windows.h is bigger and is OS dependant.


Headers, no matter how big, do not make an impact on the final size of the PE image because they are used for function and type definitions - something for the compiler. If they are used for holding functions that need compiled you are using them wrong.

Also, chances are that if you are coming to this section to learn how to program, you are doing it in a Windows environment.

If all you are trying to accomplish is attempting to contradict me, please stop, you are wasting your time.


Wow, way to take offense at something not offensive. I was only saying that time() would be more suited with cross-platform programming in mind, I didn't say your code was wrong or anything.
Back to top
View user's profile Send private message MSN Messenger
MegaForum
Grandmaster Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 558

PostPosted: Thu Jul 03, 2008 5:14 pm    Post subject: Reply with quote

noz3001 wrote:
Flyte wrote:
noz3001 wrote:
windows.h is bigger and is OS dependant.


Headers, no matter how big, do not make an impact on the final size of the PE image because they are used for function and type definitions - something for the compiler. If they are used for holding functions that need compiled you are using them wrong.

Also, chances are that if you are coming to this section to learn how to program, you are doing it in a Windows environment.

If all you are trying to accomplish is attempting to contradict me, please stop, you are wasting your time.


Wow, way to take offense at something not offensive. I was only saying that time() would be more suited with cross-platform programming in mind, I didn't say your code was wrong or anything.


I've adjusted my code and the only thing left I need is that part, having it select a random number each time. I'm willing to try your method using time() I honestly don't know how to go about using it and i tried the other method using Clock() and had no luck. Would you mind explaining it? XD
Also, do you know how I can make it so that if the person guesses it right before the 3rd try to negate the other tries and end it? Ty Smile
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Jul 03, 2008 5:16 pm    Post subject: Reply with quote

MegaForum wrote:
I've adjusted my code and the only thing left I need is that part, having it select a random number each time. I'm willing to try your method using time() I honestly don't know how to go about using it and i tried the other method using Clock() and had no luck. Would you mind explaining it? XD
Also, do you know how I can make it so that if the person guesses it right before the 3rd try to negate the other tries and end it? Ty Smile


Look at the example I posted, you can use break; to exit a loop at any time. It also shows you how to use the srand() and rand() functions.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Thu Jul 03, 2008 5:20 pm    Post subject: Reply with quote

Code:
#include <ctime>
#include <iostream>

int main( void )
{
    srand( time(0) );

    int RandomNumber = rand() % 100 + 1; // Random number between 100 & 1
    std::cout << RandomNumber;

    return 0;
}


There we go, I initially wrote it in C Razz. Messed up a bit there.


Last edited by Noz3001 on Fri Jul 04, 2008 4:03 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Jul 03, 2008 5:33 pm    Post subject: Reply with quote

noz3001 wrote:
Just re-arranged it.


Just thought I should point out you should use ctime for C++.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Thu Jul 03, 2008 5:41 pm    Post subject: Reply with quote

Flyte wrote:
noz3001 wrote:
Just re-arranged it.


Just thought I should point out you should use ctime for C++.


Yeah, i fucked up a bit and did it half and half =D
Back to top
View user's profile Send private message MSN Messenger
MegaForum
Grandmaster Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 558

PostPosted: Thu Jul 03, 2008 9:16 pm    Post subject: Reply with quote

New problem this time D;. I get this trying to compiler.

fatal error C1083: Cannot open include file: 'ctime.h': No such file or directory

~Thanks for the help~
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Jul 03, 2008 10:23 pm    Post subject: Reply with quote

MegaForum wrote:
New problem this time D;. I get this trying to compiler.

fatal error C1083: Cannot open include file: 'ctime.h': No such file or directory

~Thanks for the help~


Code:
#include <ctime>
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Fri Jul 04, 2008 5:52 am    Post subject: Re: [Help]C++ Loops Reply with quote

MegaForum wrote:
fatal error C1083: Cannot open include file: 'ctime.h': No such file or directory
#include <ctime>

slovach wrote:
<stdlib.h>
<cstdlib>

Too lazy to read all the text. Here's my version. I'll answer your questions if you have any.
Code:
/* We shall use 32-bit time on x86 machines */
#if defined(_M_IX86) || defined(i386) || defined(__i386) || defined(__i386__)
#define _USE_32BIT_TIME_T
#endif

/* You can custom these O_o */
#define tries 5
#define nMin 5
#define nMax 10

#include <iostream>
#include <sstream>
#include <cstdlib>
#include <ctime>

int main(int argc, char *argv[])
{
   ::srand( time(NULL) );
   int number[tries];
   int mynumber = (::rand() % (nMax-nMin)) + nMin;

   std::cout << mynumber << std::endl;

   std::cout << "You get " << sizeof(number) / sizeof(int) << " tries to match my number! " << nMin << "-" << nMax << std::endl;   
   
   for(int i=0; i < (sizeof(number) / sizeof(int)); ++i) {
      std::stringstream ss;

      do {
         std::cout << "Enter your number " << i+1 << ": ";
         std::string s;

         ss.clear();
         ss.str("");

         if( !std::getline(std::cin, s) )
            return EXIT_FAILURE;
         ss << s;
      } while( !(ss >> number[i]) );
      if( number[i] == mynumber ) {
         std::cout << "You got my number correct!" << std::endl;
         return EXIT_SUCCESS;
      }

      std::cout << "Your number is incorrect!" << std::endl;
   }

   std::cout << "You failed." << std::endl;

   std::cin.sync();
   std::cin.ignore();
   return EXIT_SUCCESS;
}


And few more comments about your code.
MegaForum wrote:
cin >> number;
What if I type "Jani"?
MegaForum wrote:
break;
Well.. Works, but I personally I'd try to avoid breaks in if-statements.
MegaForum wrote:
else if(number != mynumber)
No need for this.
MegaForum wrote:
cout << "Your nubmer is incorrect!" << endl;
What to say..? :P
MegaForum wrote:
system("PAUSE");
Eh.

And.. You could make your program a bit more adjustable (mins, maxs, tries)

EDIT: Uh oh.. I missed the second page again :p Whatever.
Back to top
View user's profile Send private message
MegaForum
Grandmaster Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 558

PostPosted: Fri Jul 04, 2008 9:01 am    Post subject: Reply with quote

Thanks Jani Smile. Although my code isn't as "pro" as you(neither am I) I'm going take your suggestions and fix a few things. I'm also working on making it say whether the person's input is higher or lower than the actual number ;P. Would you mind telling me how might make it so that It dissalows any character inputs and only numbers.
Thanks Razz
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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