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 


[C++]looping
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
guernica
Grandmaster Cheater Supreme
Reputation: 0

Joined: 20 Jun 2007
Posts: 1211

PostPosted: Mon Jan 28, 2008 8:48 pm    Post subject: [C++]looping Reply with quote

sorry for the excessive amount of threads that ive been bringing into this section but im a new C++ programmer and am quite inquisitive...

Code:
   cin >> response;
   if (response = 1)
      goto loop;
   
   if (response = 2)
   {
   cout << "Press the Enter key to exit";
   cin.ignore();
   cin.get();
   }


thats a snippet of code from a simple program that im making. after obtaining the value for "response", if the value is 1, then it should return to the loop at the beginning of the program. if the value is 2, then it should prompt the user to press the enter key to exit, then exit when that is done. It's obviously not correct because it just keeps looping, even when the value is changed to 2. what error have i made? keep in mind that this is my first try at loops.

_________________

georgezilka wrote:
im looking for experience (EXP) hacks for maple story are there any where it can give instant level up ?
Back to top
View user's profile Send private message Send e-mail AIM Address
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Jan 28, 2008 8:54 pm    Post subject: Reply with quote

Code:
bool bLoop = false;
cin >> responce;
if (responce == 1)
bLoop = true;
else
{
cout << "Press the enter key to exit";
cin.ignore();
cin.sync();
return 0;
}
while ( bLoop )
{
// loop your coding yea!
}

_________________
Back to top
View user's profile Send private message
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Mon Jan 28, 2008 9:17 pm    Post subject: Reply with quote

Oh yeah was just about to type the while()
_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Jan 28, 2008 9:20 pm    Post subject: Reply with quote

do NOT use GOTOS, DONOTDONOTDNOT
_________________
Back to top
View user's profile Send private message
guernica
Grandmaster Cheater Supreme
Reputation: 0

Joined: 20 Jun 2007
Posts: 1211

PostPosted: Mon Jan 28, 2008 9:22 pm    Post subject: Reply with quote

blankrider wrote:
do NOT use GOTOS, DONOTDONOTDNOT


why? i fuckin suck at this so far...

_________________

georgezilka wrote:
im looking for experience (EXP) hacks for maple story are there any where it can give instant level up ?
Back to top
View user's profile Send private message Send e-mail AIM Address
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Jan 28, 2008 9:25 pm    Post subject: Reply with quote

it's slow and bad practice. While is much better.

while(response == 1)
{
//whatever
}

_________________
Back to top
View user's profile Send private message
guernica
Grandmaster Cheater Supreme
Reputation: 0

Joined: 20 Jun 2007
Posts: 1211

PostPosted: Mon Jan 28, 2008 9:29 pm    Post subject: Reply with quote

ok thanks. would it be better to define my own function so i only have 1 line after while?
_________________

georgezilka wrote:
im looking for experience (EXP) hacks for maple story are there any where it can give instant level up ?
Back to top
View user's profile Send private message Send e-mail AIM Address
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Mon Jan 28, 2008 9:42 pm    Post subject: Reply with quote

Depends. (Note that this is my opinion, and may not be correct)

If it's a big project with a lot of functions already, it'd probably be best to just go ahead with the code all in the while loop.

If this is just something small, with maybe 1 or 2 different functions (excluding "int main()"), then go ahead and create a new function.

You could even go as far as

Code:

while(!MyLoop(MyParams))
{
     Sleep(10); //don't rape the processor
}


This is assuming that MyLoop is a method which returns a bool, and you want it to eventually return true. It also assumes that it takes the type of parameter that MyParams is. You use "Sleep(10)" as not to rape the computer's processor.

You should Google to find which library the Sleep() method is included in.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Mon Jan 28, 2008 9:45 pm    Post subject: Reply with quote

samuri25404 wrote:
You could even go as far as

Code:

while(!MyLoop(MyParams))
{
     Sleep(10); //don't rape the processor
}


Code:
for(;!MyLoop(MyParams);Sleep(10));
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Mon Jan 28, 2008 9:48 pm    Post subject: Reply with quote

Haha, even better.

Is the semi-colon needed at the end of the for-loop?

Code:

for(;!MyLoop(MyParams);Sleep(10));

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Losplagos
Expert Cheater
Reputation: 0

Joined: 21 Mar 2006
Posts: 172
Location: Knee deep in a c++ book

PostPosted: Mon Jan 28, 2008 9:51 pm    Post subject: Reply with quote

You could also use a switch. Here is a simple example
Code:

while(looping == true)
    {
           // Gets input
           std::cout << "Choose what you whant to do.\n" << "0 to quit, "
           << "1 to whatever ";
           std::cin >> c;
           switch(c) // The switch
           {
                    case 0: //Says if c = 0 exit the loop
                         looping = false; // Will stop the loop
                         std::cout << "~crys~ Will i ever see you again?\n";
                         break;
                    case 1: // same as above
                         break;
                    default:
                         std::cout << " Bad input" << std::endl;
                         break;
           }
                         
    }
}

Uses 2 loops and a bool.
Keeps the code going and is easy. This is bare if you put in something like k it will screw it up.

_________________

Earthbound = 31337
Back to top
View user's profile Send private message
guernica
Grandmaster Cheater Supreme
Reputation: 0

Joined: 20 Jun 2007
Posts: 1211

PostPosted: Mon Jan 28, 2008 9:56 pm    Post subject: Reply with quote

you've lost me.
_________________

georgezilka wrote:
im looking for experience (EXP) hacks for maple story are there any where it can give instant level up ?
Back to top
View user's profile Send private message Send e-mail AIM Address
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Jan 28, 2008 10:00 pm    Post subject: Reply with quote

samuri25404 wrote:
Haha, even better.

Is the semi-colon needed at the end of the for-loop?

Code:

for(;!MyLoop(MyParams);Sleep(10));


nope

Code:
for ( ;!MyLoop(MyParams);Sleep(10))
{
//do my stuff
}


but for now i think u should just stick with the nice while loop. simple and efficiant.

_________________
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Mon Jan 28, 2008 10:05 pm    Post subject: Reply with quote

To be simple, just put this code:

Code:

for(;!MyLoop();Sleep(10));


and define a method

Code:

bool MyLoop()
{
    cout << "Enter 0 to quit.\n";
    cout << "Enter 1 to whatever.\n";
    cin >> temp;
   
    switch(temp)
    {
        case 0: return true; //done looping
        case 1: //do whatever
             return false; //not done
        default:
              cout << "Bad input.\n".
              return false; //once again, not done looping
    }
}

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
guernica
Grandmaster Cheater Supreme
Reputation: 0

Joined: 20 Jun 2007
Posts: 1211

PostPosted: Mon Jan 28, 2008 10:10 pm    Post subject: Reply with quote

Quote:
but for now i think u should just stick with the nice while loop. simple and efficiant.


agreed. all this stuff is confusing me. ill keep it as simple as possible.

_________________

georgezilka wrote:
im looking for experience (EXP) hacks for maple story are there any where it can give instant level up ?
Back to top
View user's profile Send private message Send e-mail AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 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