#include <iostream>
using namespace std; //introduces what?
int main ( void )
{
cout << "A la ver..." ;
return 0;
}
What is wrong with this code?
Started by C.B., Dec 12 2009 03:20 PM
26 replies to this topic
#1
Posted 12 December 2009 - 03:20 PM
Simple code I was messing with. However, when I compile and Execute, it closes immediately.
|
|
|
#2
Posted 12 December 2009 - 03:55 PM
This is not the best way to do I'm sure but its the only way I know how and it works.
So just add this.
So just add this.
#include <iostream>
using namespace std; //introduces what?
int main ( void )
{
cout << "A la ver..." ;
[COLOR="Red"]system("PAUSE")[/COLOR]
return 0;
}
And I think adding namespace std; includes the standard files that way you don't have to put std:: before cout and endl. Hope I helped.:)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#3
Posted 12 December 2009 - 04:13 PM
Please do NOT use system("pause")!
The URL I provide suggests instead using cin.get(), however my suggestion is to simply get a better IDE, one that will actually pause the program at the end of it's functionality (such as Code::Blocks). If that's not an option, I'd just run the program through the command line. In this manner, you don't have to press enter each time the program runs in a production release, but you'll still see it's output either way.
The URL I provide suggests instead using cin.get(), however my suggestion is to simply get a better IDE, one that will actually pause the program at the end of it's functionality (such as Code::Blocks). If that's not an option, I'd just run the program through the command line. In this manner, you don't have to press enter each time the program runs in a production release, but you'll still see it's output either way.
Wow I changed my sig!
#4
Posted 12 December 2009 - 04:27 PM
Ok, I rewrote it using the .Cin suggestion. However now it wont compile.
Error its giving me is with the "}" saying "Expected ';' before } token.
#include <iostream>
using namespace std; //introduces what?
int main ( void )
{
cout << "A la ver..." ;
return 0;
cin.get()
}
Error its giving me is with the "}" saying "Expected ';' before } token.
#5
Posted 12 December 2009 - 04:30 PM
Yes, and you'll need to put cin.get() before the return 0; statement. Remember that every statement in C++ requires a semicolon at the end of it [noparse](;)[/noparse], and that includes cin.get(). This is basic C, so I suggest you learn how C/C++ syntax works, such as always ending statements with semicolons, placing functions within brackets, and using parenthesis with function calls.
cin.get();
return 0;
Wow I changed my sig!
#6
Posted 12 December 2009 - 04:32 PM
Thank you thank you!! I think perhaps C++ is far too advanced for a noob like me. Would you suggest a different language to begin learning on?
#7
Posted 12 December 2009 - 06:31 PM
Well I'm starting to learn Java but I want to make 2D flash games what exactly are you wanting to make games or programs?
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#8
Posted 13 December 2009 - 12:06 AM
thegamemaker said:
Well I'm starting to learn Java but I want to make 2D flash games what exactly are you wanting to make games or programs?
Capitalist as it may be. Whatever makes the most money.
#9
Posted 13 December 2009 - 12:26 AM
I hear game programing doesn't make great money enless you own the company but any way if you want to make internet flash games I would go with Java if you want real games like for a PC or Xbox360 I would learn C++ or C# which could make you some money(if your good of course)but if you want to make programs I would prbly go with C++ or maybe Python(to start with). Here is a link to a website with some free C++ and Python ebooks.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#10
Posted 13 December 2009 - 01:03 AM
@C.B. : if you want to learn about programming maybe you should start with one of the BASIC variants.. those are easier to learn than C++ or Java.. and most have good help-files. If you are serious about making money be prepared to crawl in the dark for quite some time before your work gets noted.
@thegamemaker : do you have a game planned to build with your skills or just begun toying with ideas ? I am designing a 2D game of my own which needs a lot of work, and i could use help building the game.
@thegamemaker : do you have a game planned to build with your skills or just begun toying with ideas ? I am designing a 2D game of my own which needs a lot of work, and i could use help building the game.
#11
Posted 13 December 2009 - 01:05 AM
If you are serious about making the most money programming games then you want to learn at least C++ and a scripting language like Lua or Python. This is because commercial games, either for console or pc will write all of the fast to execute portions of the program, such as the resource, event, and process managers as well as the game logic and UI in C++ for the total control of memory and other features this provides. The rest of the game like levels, story, and basic stats and such are incorporated through the use of scripts which allow less experienced programmers and developers to actually write the rest of the game.
This has multiple uses not the least of which is freeing up the programmer's time in a studio setting. The other major benefit is that the game can be fine tuned without having to recompile the entire program, since it reads in a lot of information from the script.
If you are serious about becoming a game programmer, which btw if you work for a studio you can look at close to eighty thousand a year or even more, it is a journey that will take time a lot of it. Because to be a good game programmer you need to become a good programmer first and this means understanding the machine and getting familiar with data structures and the ins and outs of the C++ language.
This has multiple uses not the least of which is freeing up the programmer's time in a studio setting. The other major benefit is that the game can be fine tuned without having to recompile the entire program, since it reads in a lot of information from the script.
If you are serious about becoming a game programmer, which btw if you work for a studio you can look at close to eighty thousand a year or even more, it is a journey that will take time a lot of it. Because to be a good game programmer you need to become a good programmer first and this means understanding the machine and getting familiar with data structures and the ins and outs of the C++ language.
#12
Posted 13 December 2009 - 06:46 AM
Ignoring all the other advice going around, perhaps an explanation is in order:
What you wrote is a console program. If you do not have the console open in advance (say, but using Start: Run: cmd), what happens is launching the program also launches the console window. It then produces its output and closes. By default, console windows close when the program they were created for closes.
The best practice, for my money, is to have your IDE open, and a console window as well. You code/compile in the IDE, but run from the console.
What you wrote is a console program. If you do not have the console open in advance (say, but using Start: Run: cmd), what happens is launching the program also launches the console window. It then produces its output and closes. By default, console windows close when the program they were created for closes.
The best practice, for my money, is to have your IDE open, and a console window as well. You code/compile in the IDE, but run from the console.


Sign In
Create Account


Back to top









