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++ query.
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
MegaForum
Grandmaster Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 558

PostPosted: Mon Jan 21, 2008 6:47 pm    Post subject: C++ query. Reply with quote

Im making a simple addition program which takes 2 intergers and add them up. My code is very noob so flame away lol.

Code:

#include <iostream>
#include <stdlib.h>
int main()
{
    cout << "Enter Firstnumber" endl;
    int Firstnumer = a
    cout << "Enter Secondnumber" endl;
    int Secondnumber= b;
    cin >> "Firstnumber + Secondnumber " end1;
    system("PAUSE");
    return 0;
}


Well can anyone tell me what im doing wrong. I have a book that i got for christmas, and i already know cin/cout commands, storing intergers/variables like so. but when it comes to coding im not sure what order to actually write it in.
PLEASE, DON'T WRITE WHAT THE CODE SHOULD BE Just tell me what im doing wrong. i wanna write ti for myself without using someone else's code Very Happy.
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 21, 2008 7:03 pm    Post subject: Reply with quote

Since you don't want answers, I will give hints.

Code:
cout << "Enter Firstnumber" endl;


You need another "<<" somewhere in there, guess. Wink

Also, if you don't put "using namespace std;" at the beginning, you must prefix each cout/cin/endl/etc with "std::".

Code:
cout << "Enter Firstnumber" endl;
    int Firstnumer = a


That is wrong, it won't store the input in "Firstnumber".

HINT: Use cin.

Code:
cin >> "Firstnumber + Secondnumber " end1;


What the hell is that?
HINT: Its just wrong, so horribly wrong.
PROTIP: "I am a string!"

Code:
system("PAUSE");


No.
Back to top
View user's profile Send private message
MegaForum
Grandmaster Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 558

PostPosted: Mon Jan 21, 2008 7:31 pm    Post subject: Reply with quote

Flyte wrote:
Since you don't want answers, I will give hints.

Code:
cout << "Enter Firstnumber" endl;


You need another "<<" somewhere in there, guess. Wink

Also, if you don't put "using namespace std;" at the beginning, you must prefix each cout/cin/endl/etc with "std::".

Code:
cout << "Enter Firstnumber" endl;
    int Firstnumer = a


That is wrong, it won't store the input in "Firstnumber".

HINT: Use cin.

Code:
cin >> "Firstnumber + Secondnumber " end1;


What the hell is that?
HINT: Its just wrong, so horribly wrong.
PROTIP: "I am a string!"

Code:
system("PAUSE");


No.


Ty for ripping my program to shreds Very Happy. i know it was crap anyways.

for
Code:
cout << "Enter Firstnumber" endl;

the other << goes at the end right?
Code:
cout << "Enter Firstnumber" << endl;



then the beginning of the code should start


#include <iostream>
#include <stdlib.h>
int main()
using namespace std;
Code:


umm for storing firstnumber im kinda lost on that. lol

and
isn't

system("PAUSE")


required so that when it shows the sum of firstnumber + secondnumber
it won't close, it'll pause and show the result?
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Jan 21, 2008 7:47 pm    Post subject: Reply with quote

cin is supposed to assign a variable a value. what you are assigning is a string
cin is used to gain a users input

system("pause") only suspends the command line until a user presses a key. but yes, it lets you see what is printed. not the best way to do so tho.

i recommend _getch(); (Hint: you have to include another header library for this function)

Hint: The "=" sign is an Assignment operator. (Assigning the Declared Variable a Value)
Hint2: "a" and "b" are not declared as integers, "firstNumber" and "secondNumber" are.
Hint3: You can get a user's input at anytime during the code, doesnt have to be after both cout's
Hint4: To store user input you must declare a space for that variable (firstNumber, and secondNumber are already declared as integers and u can use them to store the users input Wink )

to end this lets just make this straight

cout - Output ( << )
cin - Input ( >> )

_________________
Back to top
View user's profile Send private message
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Mon Jan 21, 2008 7:55 pm    Post subject: Reply with quote

-You can keep int Firstnumer if you do the same with a and use cin. Same goes for Secondnumber.
-You can get rid of one of the #include
- cin doesn't take "" or endl
- cin can take multi variables but it has to be separated by >> not +

system("pause"); will keep it from closing, it's ok, but it isn't the preferred method. The best way is to just return 0 and open it up in command prompt. If you are running vs you can just press ctrl + f5. That will keep it open if you just have a return.
Back to top
View user's profile Send private message
MegaForum
Grandmaster Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 558

PostPosted: Mon Jan 21, 2008 8:04 pm    Post subject: Reply with quote

lurc wrote:
cin is supposed to assign a variable a value. what you are assigning is a string
cin is used to gain a users input

system("pause") only suspends the command line until a user presses a key. but yes, it lets you see what is printed. not the best way to do so tho.

i recommend _getch(); (Hint: you have to include another header library for this function)

Hint: The "=" sign is an Assignment operator. (Assigning the Declared Variable a Value)
Hint2: "a" and "b" are not declared as integers, "firstNumber" and "secondNumber" are.
Hint3: You can get a user's input at anytime during the code, doesnt have to be after both cout's
Hint4: To store user input you must declare a space for that variable (firstNumber, and secondNumber are already declared as integers and u can use them to store the users input Wink )

to end this lets just make this straight

cout - Output ( << )
cin - Input ( >> )


Can you psot like a little code to tell it to sotre the users input as firstnumber and secondnumber... idk how to do that lol.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Jan 21, 2008 8:34 pm    Post subject: Reply with quote

Code:
cin >> firstNumber;


that will store the users inputted number to the variable "firstNumber" (earlier declared as an integer)

Code:
cout << firstNumber;


that will display the value of firstNumber ( if it has one yet, u'll have to assign the value using cin before the output of its value )

_________________
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 21, 2008 8:41 pm    Post subject: Reply with quote

I recommend Google'ing for a C++ tutorial for a compiler-specific tutorial, like Microsoft VC++; usually books are a bit out-dated nowadays.
_________________
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
Cx
Master Cheater
Reputation: 0

Joined: 27 Jul 2007
Posts: 367

PostPosted: Mon Jan 21, 2008 8:42 pm    Post subject: Reply with quote

Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
   int num1, num2;
   cout << "Enter first number: ";
   cin >> num1;
   cout << "\nEnter second number: ";
   cin >> num2;
   cout << "\n" << num1 << " + " << num2 << " = " << num1+num2 << endl;
   cin.ignore();
   cin.get();
   return 0;
}


Last edited by Cx on Mon Jan 21, 2008 9:28 pm; edited 1 time in total
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Mon Jan 21, 2008 8:53 pm    Post subject: Reply with quote

cstdlib, not stdlib.h
Back to top
View user's profile Send private message
XxOsirisxX
Grandmaster Cheater Supreme
Reputation: 0

Joined: 30 Oct 2006
Posts: 1597

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

Code:
"Firstnumber + Secondnumber"


Don't use " " to declare variables. Else, it will be used as String.


Code:
cout << "Enter Firstnumber" endl;
    int Firstnumer = a
    cout << "Enter Secondnumber" endl;
    int Secondnumber= b;

Is recommed to declare variables at the "start", it's a lot better to locate.

_________________

Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Tue Jan 22, 2008 8:26 am    Post subject: Reply with quote

Cx wrote:
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
   int num1, num2;
   cout << "Enter first number: ";
   cin >> num1;
   cout << "\nEnter second number: ";
   cin >> num2;
   cout << "\n" << num1 << " + " << num2 << " = " << num1+num2 << endl;
   cin.ignore();
   cin.get();
   return 0;
}
What's the #include <cstdlib> for? Oh well.. It's the thread starter's fault.
What if I type a char? What if my integer is too big to fit in int? What if num1+num2 is too big? :)
I bet you meant std::cin.sync(), not std::cin.get()?
0 isn't always EXIT_SUCCESS.
Back to top
View user's profile Send private message
MegaForum
Grandmaster Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 558

PostPosted: Tue Jan 22, 2008 1:38 pm    Post subject: Reply with quote

appalsap wrote:
cstdlib, not stdlib.h


according to my book, C++ for dummies Razz , its stdlib.h Surprised
Back to top
View user's profile Send private message
mer0x
Advanced Cheater
Reputation: 0

Joined: 06 Jan 2008
Posts: 63

PostPosted: Tue Jan 22, 2008 5:08 pm    Post subject: Reply with quote

Code:


#include <iostream>
using namespace std;

void main()
{
   int a,b;
   int c = a + b;
   printf("Enter first number");
   cin >> a;
   printf("Enter second number");
   cin >> b;
   printf("Result: %s",c);
        gets();
}
Back to top
View user's profile Send private message
Cx
Master Cheater
Reputation: 0

Joined: 27 Jul 2007
Posts: 367

PostPosted: Tue Jan 22, 2008 8:44 pm    Post subject: Reply with quote

Haha.
Funny how constructive people can be (and correctly so) about a simple console number addition program.
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