C++ In general

Alright,

When I am assigned to write code and I need to do X.

In the functions, can I call them anything?

I hate my teacher, my school and the whole frigging building.

I excel at other subjects but programming is murder!!!!!

No one helps me at all. My teacher says its like math, I have taken calculus and I understand that like abc 123. Why cant I get it?

I am doing the tutorials but its soooo hard to understand.
You can give your function any name that is considered a legal "identifier" in C++. It must start with a letter and contain only letters, numbers or the underscore character.
In the functions, can I call them anything?


Yes. the name is just a variable, like x in math.
1
2
3
int main{
return 0;
}


is the same as

1
2
3
int ImAProgram(){
return 0;
}


The only difference is the name.

int main could be f(x), g(x), h(x), or any other function name.

Where are you in the tutorial? We can try to help you through it. Don't skip parts of the tutorials, because, like math, programming builds on itself. You can't solve, for example f(g(x)), if you don't know how to multiply.
Last edited on
so if I have main.cpp do i have to have main()?
You always need a int main() function. All programs look for the main function and begin execution from there. Main can be inside a separate .cpp file, but must be included into the project. You really don't need to use separate files as a beginner but as your code becomes longer and more advanced more files help separate and organize many lines of code.
Hopefully this will help, Mr. I Need Help...

Basic Program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream> /* This is a header file. They contain a collection of functions or classes that you can call to perform specific tasks. */

/* This is the main function. The parameters in the parentheses are optional. For argv, you could
also make it "char** argv" instead. It is the same thing. */
int main(int argc, char* argv[])
{
    /* Prints "Hello, World!" to the screen and then ends the current line on the screen. The std::
    before cout and endl means that those keywords are members of the std namespace. If you
    use these keywords a lot in your programs, take out the "std::" in them and put "using
    std::member;" at the top of your file under the header they belong to, where "member" is the
    function or keyword, such as "cout". */
    std::cout << "Hello, world!" << std::endl;
    
    /* Waits for input. Gets the next character entered. You can use a char or string variable as a
    parameter to store the next character entered into that variable. */
    std::cin.get();

    /* All functions, except void functions, require a return statement. This is the data that the
    function sends back to the function that called it. Think of it as the calling function being a
    person and that person makes a phone call to another function. The person on the other end
    responds. That would be the return function. */
    return 0;
}
Last edited on
Topic archived. No new replies allowed.