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 


First program Ever Made Help

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

Joined: 02 Jan 2008
Posts: 105

PostPosted: Mon Feb 25, 2008 6:24 pm    Post subject: First program Ever Made Help Reply with quote

#include <iostream>
using namespace std;

int main() {
name, answer;

cout << "Hello there, my name is Adam.";
cout << "What is your name?";
cin >> name;
cout << "Hello " << name;
cout << "Tell me " << name;
cout << "Do you love me?";
cin >> answer;
if (answer == yes)
cout << "Aaw, I love you too Smile";
else
cout << "I don't love you at all.";
return 0;
}

Gives me a compile error with my variables "name, answer", any help would be nice D:
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Feb 25, 2008 6:34 pm    Post subject: Reply with quote

Code:
#include <iostream>
char name [255];
char answer;

int main(void){
   std::cout << "Hello there, my name is Adam, what is your name? ";
   std::cin >> name;
   std::cout << "Hello " << name << ", do you love me? ";
   std::cin >> answer;
   switch(answer){
      case 'y':
      case 'Y':
         std::cout << "Aww, I love you too!";
         break;

      default:
         std::cout << "I don't love you at all.";
         break;
   }
   return 0;
}


And to actually answer your questions... you're not defining answer and name as anything.

Also you can't just compare answer like that. In my case I'm just assuming that if the first letter is "y" that it's yes, and if it's not, then no.
Back to top
View user's profile Send private message
magiadam
Expert Cheater
Reputation: 0

Joined: 02 Jan 2008
Posts: 105

PostPosted: Mon Feb 25, 2008 6:44 pm    Post subject: Reply with quote

Error C2001: newline in constant.

And I haven't learned it yet, but why was "case 'Y':" inserted?

Thanks.
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Feb 25, 2008 6:54 pm    Post subject: Reply with quote

So they could use a capital or lowercase.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Feb 25, 2008 6:59 pm    Post subject: Reply with quote

Code:
#include <iostream>
char name [255];
char answer;

int main(void)
{
   std::cout << "Hello there, my name is Adam, what is your name\? " << std::endl;
    std::cin >> name;
   std::cout << "Hello " << name << ", do you love me\? " << std::endl;
    std::cin >> answer;
    switch(answer)
   {
       case 'y':
       case 'Y':
          std::cout << "Aww, I love you too!";
          break;
 
       default:
          std::cout << "I don't love you at all.";
          break;
   } 
   std::cin.sync();
   std::cin.ignore();
   return 0;
}


dont forget ? has to be inserted with an escape sequence: \?
and also dont forget to add new lines. and remember to add a cin.ignore/sync statement at the end so the console doesnt kill itself before ur able to read it.

the switch statement is just neater replacement for multiple if/else statements.

the equivilent would be

Code:
if ( answer != 'y' || answer != 'Y' )
std::cout << "i hate you";
else
std::cout << "i love you too";

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Feb 25, 2008 7:05 pm    Post subject: Reply with quote

Can also use strcmp

Code:

#include <iostream>

int main(void){
   char* name   = new char[255];
   char* answer = new char[255];

   std::cout << "Hello there, my name is Adam, what is your name? ";
   std::cin >> name;
   std::cout << "Hello " << name << ", do you love me? ";
   std::cin >> answer;

   if(strcmp(answer, "Yes") == 0){
      std::cout << "Aww, I love you too!";            
   }
   else{
      std::cout << "I don't love you at all.";   
   }

   return 0;
}
Back to top
View user's profile Send private message
magiadam
Expert Cheater
Reputation: 0

Joined: 02 Jan 2008
Posts: 105

PostPosted: Mon Feb 25, 2008 7:13 pm    Post subject: Reply with quote

I pressed "Ctrl + F5" and "Ctrl + Shift + B" and it doesn't create an .exe on my Visual C++ 2008. How do you make the .exe when you're finished? (Sorry for the newb questions, just bought my first C++ book this morning XD).
Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Mon Feb 25, 2008 7:16 pm    Post subject: Reply with quote

are you looking in: my documents -> visual studio 2008 -> projects -> name
Back to top
View user's profile Send private message
magiadam
Expert Cheater
Reputation: 0

Joined: 02 Jan 2008
Posts: 105

PostPosted: Mon Feb 25, 2008 7:18 pm    Post subject: Reply with quote

1>------ Build started: Project: FirstProg2, Configuration: Debug Win32 ------
1>Compiling...
1>FirstProg2.cpp
1>.\FirstProg2.cpp(1) : error C2001: newline in constant
1>Build log was saved at "file://c:\Documents and Settings\Adam\My Documents\Visual Studio 2008\Projects\FirstProg2\FirstProg2\Debug\BuildLog.htm"
1>FirstProg2 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

So there must be an error in the script o__o

And

slovach wrote:
are you looking in: my documents -> visual studio 2008 -> projects -> name


Yes I did, nothing.
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