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++ coding help

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

Joined: 07 Dec 2007
Posts: 43

PostPosted: Mon Sep 15, 2008 9:25 pm    Post subject: c++ coding help Reply with quote

ok im trying to self teach my self c++ but i have run into a problem i need to subract 2 strings to make another string heres the code.

Code:
// first practice game.

#include <iostream>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;

int main()
{
    int pies, ate, fed, remaining;
    string leader;
   
    cout << "enter a number from 2 to 1,000,000,000: ";
    cin >> pies;
   
    cout << "you have " << pies << " pies" <<  endl;
   
    cout << "enter a smaller number than " << pies << endl;
    cin >> ate;
   
    cout << "you ate " << ate <<  "  pies" << " you now have " << pies - ate = remaining << endl;
   
    cout << "now enter a number smaller than " << remaining << endl;
   
    cout << "press enter 2 times to exit" << endl;
    cin.ignore(cin.rdbuf()->in_avail() + 3);
   
    return 1;
}
Back to top
View user's profile Send private message
xV
I post too much
Reputation: 1

Joined: 03 Jan 2008
Posts: 3783
Location: Seattle

PostPosted: Mon Sep 15, 2008 9:56 pm    Post subject: Reply with quote

Remove all that using Namespace garbage.




Code:

using namespace std;


(pies)-(ate)

lol

_________________
Back to top
View user's profile Send private message MSN Messenger
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Mon Sep 15, 2008 10:00 pm    Post subject: Reply with quote

You need to learn about different data types. declare them in as int instead of string.
Code:
 cout << "you ate " << ate <<  "  pies" << " you now have " << pies - ate = remaining << endl;

You can't store expressions like that in another command. and you've also got it backwards.
Code:
 remaining = pies - ate
cout << "you ate " << ate <<  "  pies" << " you now have " << remaining << endl;


The reason for tutorials is not ending up stuck like this. Pick a tutorial and follow it, atleast until you get a strong command of the language. then, and only then can you go off and do whatever you want. Answering questions like this that could be solved by looking at a tutorial will get old fast.

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

Joined: 16 Jun 2006
Posts: 551

PostPosted: Mon Sep 15, 2008 10:02 pm    Post subject: Reply with quote

Code:
// first practice game.

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int pies, ate, fed, remaining;
    string leader;
   
    cout << "enter a number from 2 to 1,000,000,000: ";
    cin >> pies;
   
    cout << "you have " << pies << " pies" <<  endl;
   
    cout << "enter a smaller number than " << pies << endl;
    cin >> ate;
   remaining = pies -ate;
    cout << "you ate " << ate <<  "  pies" << " you now have " << remaining << endl;
   
    cout << "now enter a number smaller than " << remaining << endl;
     // you didnt put a cin >> to take in a smaller number than remaining here
    cout << "press enter 2 times to exit" << endl;
    cin.ignore(cin.rdbuf()->in_avail() + 3); // uhm....wtf? what are you trying to do here?
   
    return 0;
}


also, you made no attempt to use the string "leader", so why declare it?

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

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Mon Sep 15, 2008 10:06 pm    Post subject: Reply with quote

@vibes
The problem with including the entire namespace is that it bloats the executable. bucky is doing the correct thing in setting up only the few functions that he uses.

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

Joined: 07 Dec 2007
Posts: 43

PostPosted: Tue Sep 16, 2008 12:01 am    Post subject: Reply with quote

thank you for the help Smile
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
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