Jump to content

What is wrong with this code?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
26 replies to this topic

#1
C.B.

C.B.

    Newbie

  • Members
  • PipPip
  • 12 posts
Simple code I was messing with. However, when I compile and Execute, it closes immediately.

#include <iostream>

using namespace std; //introduces what?

int main ( void )

{

    

    cout << "A la ver..." ;

    return 0;

}


#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
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.
#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.

#3
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
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.
Wow I changed my sig!

#4
C.B.

C.B.

    Newbie

  • Members
  • PipPip
  • 12 posts
Ok, I rewrote it using the .Cin suggestion. However now it wont compile.

#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
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
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
C.B.

C.B.

    Newbie

  • Members
  • PipPip
  • 12 posts
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
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
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.

#8
C.B.

C.B.

    Newbie

  • Members
  • PipPip
  • 12 posts

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
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
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.

#10
nexus-6

nexus-6

    Newbie

  • Members
  • PipPip
  • 14 posts
@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.

#11
SolidState

SolidState

    Learning Programmer

  • Members
  • PipPipPip
  • 38 posts
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.

#12
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
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.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog