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 


New to C++

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

Joined: 18 Sep 2007
Posts: 87

PostPosted: Fri Apr 11, 2008 9:47 pm    Post subject: New to C++ Reply with quote

Hey guys, I tried cplusplus.com but they seem to take two hours to reply and I thought Cheat Engine would be much better. Well as the title says, I'm pretty new to C++. Earlier I felt like I was actually starting to understand it so I decided to go ahead and try to make a rather simple program.

The ideas of the program was to allow the user to input letters for their name one at a time. And if they entered in a valid one, then it would allow them to put in the next and the next and so on. If you wanted to terminate the program you would be able to type in end. At the end of this all once you type in finish, it would out put all the letters you put together. I had this idea and thought it would be pretty cool if I could do it. I've made some alternatives since my other plans hadn't worked. But I'd like to know your guys' ideas on this.

So far this is what I got:

Code:


#include <iostream>

using namespace std;

int main ()
{
   char a, b, c;
   int x;
   
   cout << "Hello, please enter in the first letter of your name then follow by hitting enter and placing the next letter." << endl;
   cin >> a;
   cout << "Did you put " << a << "?" << endl;
   cout << "Hit 1 for yes, hit two for no" << endl;
   cin >> x;
   
   if (x == 1)
      cout << "Please put in next number" << endl;

   else if (x == 2)
      cout << "Returning to beginning" << endl;

}



Its not much because I have no idea where to go from there. I tried to make it so it can end and more but I'm only posting what worked...other then that I feel kind of hopeless. Or am I just doing it all wrong? Any help?
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Apr 11, 2008 9:51 pm    Post subject: Reply with quote

edit: so as I was saying before my internet shit the bed.

sounds like you're in need of 'strcmp'

Code:
#include <iostream>
char input[10];
char name[50];
int i;

int main ()
{
   std::cout << "Hello, please enter in the first letter of your name then follow by hitting enter and placing the next letter." << std::endl;
   do{
      std::cin >> name[i];
      std::cout << "Did you input '" << name << "' so far?" << std::endl;
      std::cout << "Enter '1' for yes, '2' for no or 'finish' to end it." << std::endl;
      std::cin.sync();
      std::cin >> input;
      if(strcmp(input, "finish") == 0){
         break;
      }

      switch(input[0]){
         case '1':
            std::cout << "Please put in next letter." << std::endl;
            i++; break;
         case '2':
            std::cout << "Returning to beginning." << std::endl;
            for(i = 0; i < 50; i++){
               name[i] = 0;
            }break;
         default:
            std::cout << "Don't shart your jorts, bro.";
            break;
      }
   }while(strcmp(input, "finish") != 0);
   std::cout << "May all yo poppin' be followed by equal quantities of lockin, " << name;
   std::cin.sync();
   std::cin.ignore();
   return 0;
}
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Sun Apr 13, 2008 12:21 pm    Post subject: Reply with quote

slovach wrote:
sounds like you're in need of 'strcmp'
Use std::string and you don't need strcmp.
Back to top
View user's profile Send private message
Chaosis13
Master Cheater
Reputation: 0

Joined: 14 Aug 2007
Posts: 372

PostPosted: Sun Apr 13, 2008 1:16 pm    Post subject: Reply with quote

You need to learn about loops.
Like:

for (int x = 0; x = 10; x++){
stuff
}

do {
stuff
} while (x = 1)

while (x = 1) {
stuff
}

There are some more, and ways to get fancy with them. But use the do-while for something you want to run at least once, the while for when you want to see if something changes, and the for if you want x to equal all but some... You can also use || (or) and && (and) with your loops.

P.S. Get a good book from a used books store, you will learn C++ alot better. And PM me or post if you have any other questions.
Back to top
View user's profile Send private message
podr
How do I cheat?
Reputation: 0

Joined: 27 Feb 2008
Posts: 2

PostPosted: Sun Apr 13, 2008 7:24 pm    Post subject: Reply with quote

Code:
#include <iostream>
#include "apstring.h" // just google "apstring.h" and "apstring.cpp"

using namespace std;

int main ()
{
   int i = 0;
   apstring myName;
   cout << "Hello, please enter your name" << endl;
   cin >> myName;
   cout << "Welcome, " << myName << " to MyFirstProg! \nHere is your name spelled out for you!" << endl;
   while(i <= myName.length())
   {
       cout << myName[i] << " "; // space out the letters,
       i++;
   }

}
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Apr 14, 2008 8:52 am    Post subject: Reply with quote

@podr: Why use apstrings? They are nothing more then a rewritten std::string class that offers little to no advances over the original string class. Also the example you posted was not what the original poster was looking for from my understanding of his post. slovach's example is what I would figure he wanted.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
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