Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualdejaime

Posted 02 February 2014 - 06:22 PM

My program has SFML so I am not going to post that code but here is simple version of what I mean

#include <iostream>

using namespace std;

int main()
{
    void function();
    {
        cout << "Hello world!" << endl;
    }

    return 0;
}

The program will say Hello World
but I want it to only run when i call the function later on
How do I stop that?

 

I see the problem, as previously noted by Paradigm Shifter and Washu, you're not coding a "function inside main".
What you are doing is declaring a function:
 

void function(); // Notice that ";", it marks the end of the function declaration

 
 
and then adding "Hello World!" to cout.

{
    cout << "Hello World!" << endl;
}

the { and } are just block separators, that you can use to limit scopes, between some other things.
So the function and the { cout } aren't related by any means.


#5dejaime

Posted 02 February 2014 - 04:32 PM

My program has SFML so I am not going to post that code but here is simple version of what I mean

#include <iostream>

using namespace std;

int main()
{
    void function();
    {
        cout << "Hello world!" << endl;
    }

    return 0;
}

The program will say Hello World
but I want it to only run when i call the function later on
How do I stop that?

I see the problem, as previously noted by Washu, you're not coding a "function inside main".
What you are doing is declaring a function:
 
void function(); // Notice that ";", it marks the end of the function declaration
 
 
and then adding "Hello World!" to cout.
{
    cout << "Hello World!" << endl;
}
the { and } are just block separators, that you can use to limit scopes, between some other things.
So the function and the { cout } aren't related by any means.

#4dejaime

Posted 02 February 2014 - 04:32 PM

My program has SFML so I am not going to post that code but here is simple version of what I mean

#include <iostream>

using namespace std;

int main()
{
    void function();
    {
        cout << "Hello world!" << endl;
    }

    return 0;
}

The program will say Hello World
but I want it to only run when i call the function later on
How do I stop that?

I see the problem, as previously noted by Washu, you're not coding a "function inside main".
What you are doing is declaring a function:
 
void function(); // Notice that ";", it marks the end of the function declaration
 
 
and then adding "Hello World!" to cout.
{
    cout << "Hello World!" << endl;
}
the { and } are just block separators, that you can use to limit scopes or between some other things.
So the function and the { cout } aren't related by any means.

#3dejaime

Posted 02 February 2014 - 04:32 PM

My program has SFML so I am not going to post that code but here is simple version of what I mean

#include <iostream>

using namespace std;

int main()
{
    void function();
    {
        cout << "Hello world!" << endl;
    }

    return 0;
}

The program will say Hello World
but I want it to only run when i call the function later on
How do I stop that?

I see the problem, as previously noted by Washu, you're not coding a "function inside main".
What you are doing is declaring a function:
 
void function(); // Notice that ";", it marks the end of the function declaration
 
 
and then adding "Hello World!" to cout.
    cout << "Hello World!" << endl;
the { and } are just block separators, that you can use to limit scopes or between some other things.
So the function and the { cout } aren't related by any means.

#2dejaime

Posted 02 February 2014 - 04:31 PM

My program has SFML so I am not going to post that code but here is simple version of what I mean

#include <iostream>

using namespace std;

int main()
{
    void function();
    {
        cout << "Hello world!" << endl;
    }

    return 0;
}

The program will say Hello World
but I want it to only run when i call the function later on
How do I stop that?

I see the problem, as previously noted by Washu, you're not coding a "function inside main".
What you are doing is declaring a function:
 
void function(); // Notice that ";", it marks the end of the function declaration
 
 
and then adding "Hello World!" to cout.
    cout << "Hello World!" << endl;
the { and } are just block separators, that you can use to limit scopes or between some other things.
But the function and the { cout } aren't related by any means.

#1dejaime

Posted 02 February 2014 - 04:31 PM

My program has SFML so I am not going to post that code but here is simple version of what I mean

#include <iostream>

using namespace std;

int main()
{
    void function();
    {
        cout << "Hello world!" << endl;
    }

    return 0;
}

The program will say Hello World
but I want it to only run when i call the function later on
How do I stop that?

I see the problem, as previously noted by Washu, you're not coding a "function inside main".
What you are doing is declaring a function:
 
void function(); // Notice that ";", it marks the end of the function declaration
 
 
and then adding "Hello World!" to cout.
    cout << "Hello World!" << endl;
the { and } are just block separators, that you can use to limit scopes or between some other things.
But the function and the { cout } aren't related by any means.

PARTNERS