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++ error
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
famousmassacre1
Expert Cheater
Reputation: 0

Joined: 30 Jun 2008
Posts: 113
Location: San Antonio Texas

PostPosted: Wed Aug 06, 2008 9:28 am    Post subject: C++ error Reply with quote

i keep getting an error on this code but i cant find whats wrong
Code:

// This is a comment
// This program will accept and display their sum

#include <iostream.h>

void main()
{
 // Define variables
 float num1;
 float num2;
 float total;
 
 // Enter data for variables
 cout << "10";
 cin >> num1;
 cout << "9";
 cin >> num2;
 
 // Add the two numbers together
 total = num1 + num2;
 
 // Display the result
 cout << "The sum of the numbers = " << total;
 
}
[/code]
_________________


Last edited by famousmassacre1 on Wed Aug 06, 2008 9:43 am; edited 1 time in total
Back to top
View user's profile Send private message
jackyyll
Expert Cheater
Reputation: 0

Joined: 28 Jan 2008
Posts: 143
Location: here

PostPosted: Wed Aug 06, 2008 9:40 am    Post subject: Reply with quote

First, you should use [code] tags when posting code.. Second, when asking about an error you get, it is very helpful if you.. Post the error your getting..

So post the error you are getting and i will try and help you fix it..
Back to top
View user's profile Send private message AIM Address MSN Messenger
famousmassacre1
Expert Cheater
Reputation: 0

Joined: 30 Jun 2008
Posts: 113
Location: San Antonio Texas

PostPosted: Wed Aug 06, 2008 9:42 am    Post subject: Reply with quote

how do i post the error i dont know he error i just cant compile it then run it
_________________
Back to top
View user's profile Send private message
jackyyll
Expert Cheater
Reputation: 0

Joined: 28 Jan 2008
Posts: 143
Location: here

PostPosted: Wed Aug 06, 2008 9:46 am    Post subject: Reply with quote

Well, if you're using visual studio to compile it would show the error in the output panel near the bottom of the screen. So just copy paste that or write it out if it doesn't let you..
Back to top
View user's profile Send private message AIM Address MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Wed Aug 06, 2008 9:51 am    Post subject: Reply with quote

View -> Error List.

or

Ctrl + W + E

_________________
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
Typhoon808
Expert Cheater
Reputation: 0

Joined: 27 Mar 2008
Posts: 175
Location: Wales

PostPosted: Wed Aug 06, 2008 9:54 am    Post subject: Reply with quote

The error is probably about undefined words, correct?

Add std:: to the beginning of cout.
Back to top
View user's profile Send private message
famousmassacre1
Expert Cheater
Reputation: 0

Joined: 30 Jun 2008
Posts: 113
Location: San Antonio Texas

PostPosted: Wed Aug 06, 2008 10:05 am    Post subject: Reply with quote

should i get visual C++ cuz ppl here said its horrible
_________________
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Wed Aug 06, 2008 10:07 am    Post subject: Reply with quote

Typhoon808 wrote:
The error is probably about undefined words, correct?

Add std:: to the beginning of cout.
He's using iostream.h... And that's also his problem I guess. Modern compilers don't have that obsolete file anymore.
Code:
#include <iostream>
using std::cout;
using std::cin;
Btw.. Get a more recent book :P
Code:
#include <iostream>

int main(int argc, char *argv[])
{
   float num1, num2;

   std::cout << "Num1: ";
   std::cin >> num1;
   std::cout << "Num2: ";
   std::cin >> num2;
   
   std::cout << "The sum of the numbers is " << num1+num2;

   return EXIT_SUCCESS;
}


Last edited by Jani on Wed Aug 06, 2008 10:15 am; edited 1 time in total
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: Wed Aug 06, 2008 10:14 am    Post subject: Reply with quote

Ahhhhhhh, you're using a very outdated tutorial. Find a new one before continuing.
Code:
#include <iostream> //no need for .h

int main() //int, not void
//...etc


cout and cin are part of the std namespace. In order to use them, you have to tell the compiler those are the functions you mean. You can either put
Code:
using namespace std;

directly under your includes which will include the entire std namespace in your program which is entirely unnecessary. Or you can prefix cin an cout with std::. As in
Code:
std::cout << "stuff";
std::cin >> avar;

Which is a lot better once you get used to reading it that way.

You're also not pausing the program after it's done. Use
Code:
std::cin.get();

at the end of the program to wait for unput from the user before continuing.
You should also put
Code:
return EXIT_SUCCESS

at the end of the program instead of just the closeing bracket.

_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Wed Aug 06, 2008 10:14 am    Post subject: Reply with quote

famousmassacre1 wrote:
should i get visual C++ cuz ppl here said its horrible


Yes you should get it. It's probably the best compiler out there. And nobody here said VC++ sucks, they said Dev-C++ sucks. And you should find a new tutorial if they're teaching you to use iostream.h. And as people s tated your problem is you're not putting std:: in front of your cin and cout. The thing is the iostream header file has the standard namespace (std) in it, which holds the functions such as cout and cin. So you can either say you're going to use it with this line of code:

Code:

using namespace std; //your gonna use the namespace so you can do this

//now you dont have to use std::cout and std::cin

cout<<"bla";
cin>>bla;


Otherwise you have to put std:: in front of cout and cin so that your compiler knows your referencing functions from the standard namespace.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Wed Aug 06, 2008 10:17 am    Post subject: Reply with quote

HalfPrime wrote:
You're also not pausing the program after it's done.
Pausing is for stupid noobs who don't know how to use console >_> You should NEVER pause your program that way..
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Wed Aug 06, 2008 10:18 am    Post subject: Reply with quote

How do you suggest then Jani? Because most people do use either this:

Code:

cin.get();


or this:

Code:

cin.sync();
cin.get();


And please don't say system("PAUSE").

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
famousmassacre1
Expert Cheater
Reputation: 0

Joined: 30 Jun 2008
Posts: 113
Location: San Antonio Texas

PostPosted: Wed Aug 06, 2008 10:33 am    Post subject: Reply with quote

i really dont understand i started C++ yesterday and im only 12 but have been programming for a long time
_________________
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Wed Aug 06, 2008 10:37 am    Post subject: Reply with quote

Add me on msn and I'll explain the stuff you don't understand.
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Aug 06, 2008 11:06 am    Post subject: Reply with quote

Code:
std::cin.sync();
std::cin.ignore();


To pause.

_________________
- 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
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