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 


My C++ code
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
mydogjax
Master Cheater
Reputation: 0

Joined: 11 Aug 2007
Posts: 314

PostPosted: Fri Apr 10, 2009 9:09 pm    Post subject: My C++ code Reply with quote

How does this look for my first code?

Code:
 #include <iostream>

using namespace std;

int main()
{
  int thisisanumber;

  cout<<"Pick a number between 1 and 10: ";
  cin>> thisisanumber;
  cin.ignore();
  cout<<"You entered: "<< thisisanumber <<"\n";
  if (thisisanumber == 5)
     cout<<"Ha ha, you guessed correctly!";
  else if (thisisanumber < 5)
     cout<<"Too low, nub. Try again";
   if (thisisanumber > 5)
     cout<<"too high!";
  cin.get();
}

_________________
i loled hard at this
Back to top
View user's profile Send private message
talkerzero
Grandmaster Cheater
Reputation: 1

Joined: 24 Jul 2008
Posts: 560
Location: California

PostPosted: Fri Apr 10, 2009 10:04 pm    Post subject: Reply with quote

1. You may want it to loop. If it's going to end ri ght away then telling them that they guessed the wrong number won't help them (well in this case it will, because the correct number is always 5, but they don't know that). You can loop using while or for, but if it's your first code you may not have gotten as far as loops yet.

2.
Code:
cin>> thisisanumber;
cin.ignore();

Since you already have cin>> thisisanumber there is no need for the cin.ignore.

3. You should always return a value. (with return)
Back to top
View user's profile Send private message Visit poster's website
VolatileAce
Cheater
Reputation: 0

Joined: 19 Mar 2009
Posts: 30
Location: 0001001100110111

PostPosted: Fri Apr 10, 2009 10:07 pm    Post subject: Reply with quote

Pretty good.

You forgot to put 'return 0;'.
Its better to use one or two word variable names then this-is-a-number.
You should put a else before ' if (thisisanumber > 5) ';[/code]
Back to top
View user's profile Send private message
talkerzero
Grandmaster Cheater
Reputation: 1

Joined: 24 Jul 2008
Posts: 560
Location: California

PostPosted: Fri Apr 10, 2009 10:31 pm    Post subject: Reply with quote

Code:
#include <iostream>

using namespace std;

int main()
{
   int nVariable = 0;

   for(;;) //infinite loop
   {
      cout << "Pick a number between 1 and 10: ";
      cin >> nVariable;
      cout << "You entered " << nVariable << "\n";
      if(nVariable == 5)
         cout << "Ha ha, you guessed correctly!";
      else if(nVariable < 5)
         cout << "Too loo, nub. Try again";
      else if(nVariable > 5)
         cout << "too high!";
      cout << "\n"
   }

   return EXIT_SUCCESS;
}
Back to top
View user's profile Send private message Visit poster's website
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Fri Apr 10, 2009 11:12 pm    Post subject: Reply with quote

Code:
#include <iostream>

using namespace std;

int main()
{
   int nVariable = 0;
   cout << "Pick a number between 1 and 10: ";
    for(;;) //infinite loop
   {
     
      cin >> nVariable;
      cout << "You entered " << nVariable << ".\n";
      if(nVariable == 5)
         cout << "Ha ha, you guessed correctly! \n";
      else if(nVariable < 5)
         cout << "Too loo, nub. Try again  \n";
      else if(nVariable > 5)
         cout << "Too high! Try again  \n";
   }

   return EXIT_SUCCESS; // same as return 0;
}


Just a minor conceptual change to talker0's
Back to top
View user's profile Send private message
VolatileAce
Cheater
Reputation: 0

Joined: 19 Mar 2009
Posts: 30
Location: 0001001100110111

PostPosted: Sat Apr 11, 2009 12:06 am    Post subject: Reply with quote

manc wrote:
Code:
#include <iostream>

using namespace std;

int main()
{
   int nVariable = 0;
   cout << "Pick a number between 1 and 10: ";
    for(;;) //infinite loop
   {
     
      cin >> nVariable;
      cout << "You entered " << nVariable << ".\n";
      if(nVariable == 5)
         cout << "Ha ha, you guessed correctly! \n";
      else if(nVariable < 5)
         cout << "Too loo, nub. Try again  \n";
      else if(nVariable > 5)
         cout << "Too high! Try again  \n";
   }

   return EXIT_SUCCESS; // same as return 0;
}


Just a minor conceptual change to talker0's


You don't need to initialize nVariable for more optimized code.
Also weren't you suppose to exit the loop once you get 5?

Code:
void main(){
    int i;
    cout << "Pick a number between 1 and 10: " << endl;
    do{
        cin >> i;
        cout << "You entered " << i << "." << endl << (i - 5 ? i < 5 ? "Too low, try again:" : "Too high, try again:" : "Ha ha, you guessed correctly!") << endl;
    }while(i^5);
}
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sat Apr 11, 2009 12:42 am    Post subject: Reply with quote

holy shit
thats badass

mind explaining real quick?

Code:
cout << (i - 5 ? i < 5 ? "Too low, try again:" : "Too high, try again:" : "Ha ha, you guessed correctly!");


I didnt know you could do that three ways, i had only known of true or false.
What are you three statements from
Code:
i - 5 ? i < 5 ?

sorry kinda burnt right now Razz


Code:
while(i^5)


how do you say this condition?
while i is ??? to 5 ?
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Apr 11, 2009 1:11 am    Post subject: Reply with quote

Well, since we are having a contest to see who can write the best code, I decided to take it in another direction. Mine is invariably the best because the main code section resembles a pokeball*. At the end it then prints itself out in recognition of what I have done.

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

char *lol[] = { \
"                    using std::cin;", \
"               int main(){int t=time(0);", \
"          ::srand(t);int a,i,r=(::rand()%10)+1; ", \
"      std::cout<<\"Pick a number between 1 and 1\";", \
"    std::cout << \"0\\n\";do{std::cin>>a;std::cout<<\"Y\";", \
"    std::cout << \"ou entered \" << a << \".\"  <<std::endl; ", \
"   if(a==r){std::cout<<\"Ha ha, you guessed correctly!\\n\";", \
"  }else if(a < r){std::cout     <<\"Too low, idiot. You \" ;", \
"  ////////////////////////       /////////////////////////", \
"  std::cout<<\"wh\";std::cout     << \"ited out! =(\" << \"\\n\"; ", \
"   } else if(a>r){ std::cout <<\"T\"; std::cout << \"oo h\";", \
"    std::cout << \"igh! You whi\"; std::cout << \"ted o\";", \
"     std::cout << \"ut!\";std::cout << \"=(\" << \"\\n\";}}", \
"       while(a!=r);for(int i=0;i<11+1+1+1+1+1;i++){", \
"           std::cout << lol[i] << std::endl; }", \
"              cin.sync();std::cin.ignore(); ", \
"                  return EXIT_SUCCESS; }" };

                using std::cin;
            int main(){int t=time(0);
         ::srand(t);int a,i,r=(::rand()%10)+1;
      std::cout<< "Pick a number between 1 and 1";
    std::cout << "0\n";do{std::cin>>a;std::cout<<"Y";
    std::cout << "ou entered " << a << "."  <<std::endl;
   if(a==r){std::cout<<"Ha ha, you guessed correctly!\n";
  }else if(a < r){std::cout     <<"Too low, idiot. You " ;
  ////////////////////////       /////////////////////////
  std::cout<<"wh";std::cout     << "ited out! =(" << "\n";
   } else if(a>r){ std::cout <<"T"; std::cout << "oo h";
    std::cout << "igh! You whi"; std::cout << "ted o";
    std::cout << "ut!";std::cout << "=(" << "\n";}}
      while(a !=r);for(i=0; i<11+1+1+1+1+1; i++){
         std::cout << lol[i] << std::endl; }
             cin.sync();std::cin.ignore();
                 return EXIT_SUCCESS; }


*best viewed in size 11 consolas.
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sat Apr 11, 2009 1:28 am    Post subject: Reply with quote

You give me a reason to browse this board Embarassed
Back to top
View user's profile Send private message
VolatileAce
Cheater
Reputation: 0

Joined: 19 Mar 2009
Posts: 30
Location: 0001001100110111

PostPosted: Sat Apr 11, 2009 6:01 am    Post subject: Reply with quote

@Flyte: Win, lmao.

@manc
Code:
cout << (i - 5 ? i < 5 ? "Too low, try again:" : "Too high, try again:" : "Ha ha, you guessed correctly!");


In C++, any non-zero value is considered "true".
The ? : is a ternary operator, basically similar to a shortened if else that returns some sort of value.
(Note: The i - 5.. just to make it look pretty, i == 5 will produce faster code)

Example:
Code:
int i = x < y ? x : y;


That would assign the smaller of the value (x and y) to i.

Code:
while(i^5)


While i Xor 5.
Just using Xor's basic properties. Any value Xor'ing itself will return 0.
Xor'ing should be faster then cmp. (I could be wrong)


Hope this helps.
Back to top
View user's profile Send private message
->:Key:
Advanced Cheater
Reputation: 0

Joined: 27 Sep 2008
Posts: 74
Location: Information Not For Disclosure

PostPosted: Sat Apr 11, 2009 7:32 am    Post subject: Reply with quote

o: I has Bordom

Code:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h>
using namespace std;


void main()
{
   int rNum;
    srand((unsigned)time(0)); 
    rNum = (rand()%100)+1;

   cout << "Think Of a Number" << endl;
   cin.get();
   system("CLS");
   cout << "Now Times It By 2" << endl;
   cin.get();
   system("CLS");
   cout << "Now Add: " << rNum << endl;
   cin.get();
   system("CLS");
   cout << "Now Divide It By 2" << endl;
   cin.get();
   system("CLS");
   cout << "Minus The Number You Though Up" << endl;
   cin.get();
   system("CLS");
   rNum /= 2;
   cout << "The Number You are Thinking Of is: " << rNum << endl;
   cin.get();
}


Cred - Gramps for trick
me for somthing
Back to top
View user's profile Send private message
mydogjax
Master Cheater
Reputation: 0

Joined: 11 Aug 2007
Posts: 314

PostPosted: Sat Apr 11, 2009 9:02 am    Post subject: Reply with quote

This thread has gone beyond my knowledge of C++ Confused
_________________
i loled hard at this
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sat Apr 11, 2009 9:10 am    Post subject: Reply with quote

mydogjax wrote:
This thread has gone beyond my knowledge of C++ Confused


Ask, and you shall recieve Surprised
Back to top
View user's profile Send private message
mydogjax
Master Cheater
Reputation: 0

Joined: 11 Aug 2007
Posts: 314

PostPosted: Sat Apr 11, 2009 9:37 am    Post subject: Reply with quote

Ok, so if how do i make it loop? Whats the syntax for it?
_________________
i loled hard at this
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sat Apr 11, 2009 9:55 am    Post subject: Reply with quote

mydogjax wrote:
Ok, so if how do i make it loop? Whats the syntax for it?


You could use for, while, or goto. That's all I know of Neutral
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 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