Okay, so I created a new project.I created 2 files in it. The first one, ran well and good. The second one's code has no errors, and it compiles alright. But when I try to run it, it switches back to the previous file and gives error.
Code of the second file:
#include<iostream>
float temp(float);
int main()
{
using namespace std;
float celsius;
cout<<"Enter the temperature in celsius: ";
cin>>celsius;
cout<<celsius<<" degree celsius is equal to "<< temp(celsius) << " degree fahrenheit.";
return 0;
}
float celsius(float a)
{
return 1.8*a + 32.0;
}
Build Log after I run it. (No error in compiling it)
-------------- Build: Debug in Learning C++ ---------------
Linking console executable: bin\Debug\Learning C++.exe
obj\Debug\stone_lb.o: In function `main':
D:/Documents and Settings/Manish/My Documents/CodeBlocks/Learning/Project_Learning/Learning C++/stone_lb.cpp:4: multiple definition of `main'
obj\Debug\temp_convrt.o:D:/Documents and Settings/Manish/My Documents/CodeBlocks/Learning/Project_Learning/Learning C++/temp_convrt.cpp:4: first defined here
obj\Debug\temp_convrt.o:temp_convrt.cpp:(.text+0x3e): undefined reference to `temp(float)'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
3 errors, 0 warnings
Why is it trying to link this new file to the previous one. The build message is saying that I have 'multiple definitions of main()' I'm assuming that because they are in the same project, C::B is trying to compile and run them together or something?
When this happened a few hours back, the second file was compiling without errors, but the O/P was of the file. I restarted, and then the above mentioned problem started. I've searched and found an old thread with the same problem, but no solution.
Again, don't think there's any problem with the code. Earlier I simply used to open empty files. Now I started putting them in a project and this happens.
Any help is appreciated.