Hi all,
I've just started learning C++. Basically I wish to try out some basic C++ codes and operations in Codeblocks. I created a project under which I intend to put all the C++ programs in. The default ''Hello world'' program runs fine- but whenever I try to run the second program that I have written under the same project, I get an error saying ''multiple definition of 'main'...first defined here..'' .
Does this mean I have to create a new project everytime I want to run a single program? :/ Is there a better way to do what I'm trying to do here?

Does this mean I have to create a new project everytime I want to run a single program?

Yes.

If you made chili in a pot yesterday, would you want to make tomato soup today in the same pot with the leftover chili?
You either
1) clean out your pot
2) or get a new one.

Comments
haha, nice one! ;)
haha nice =)

Walt is right, i suggest you work directly without making a project for such basic programs.
whenever you make a new program write it separately in a new cpp file..

what you can do is to seperate the program into functions.

.
.
.
int main(){
    func();
    other();
    dothis();
}

void func(){
    //do your stuff
}
void other(){
    //do your stuff
}
void dothis(){
    //do your stuff
}

incase you dont know what functions are i suggest you skip to that chapter and read about it
before doing anything else.

(the void infront of the functions name means that the function returns nothing)
and if you want to run one "program" just call its function and not the all 3
good luck learning!

Walt is right, i suggest you work directly without making a project for such basic programs.
whenever you make a new program write it separately in a new cpp file..

Yep- That's exactly what I'm doing now. I was only trying to do how I did things in Java in my previous course- where in Netbeans I created separate projects or folders for multiple programs topicwise ie methods, strings, arrays, objects... and so on.
Thanks for all the help :)

This article has been dead for over six months. Start a new discussion instead.