Why will this not run?

I am making this program for school, and I cant figure out why the program wouldn't run. The Debug report, is as follows:

Calculator.obj : error LNK2005: _main already defined in Calc.obj
1>C:\C++\Zach\C++\Favorite_Number\Debug\Calculator.exe : fatal error LNK1169: one or more multiply defined symbols found

The code that I have is this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  // Favorite Number program
 
// Include the iostream library
#include <iostream>
 
//Use the standard namespace
using namespace std;
 
void main ( )
{
   // Declare the variables
   float Favorite_Number;
 
   // Give instructions
   cout << "Try to Guess My Favorite Number!" << endl;
   cin >> Favorite_Number;
   // Get numbers
   
   if (Favorite_Number == 13)

   // Print responce to getting the answer correct
   cout << "Amazing! How did you guess that?!?!" << endl;
 
   system ("PAUSE");


Any help?
try to change void main to int main
It would appear you have two main functions on the same program - there should be only one. You are also short in the code you provided us with.
Last edited on
That is all the code I have input, and I only see one void main function, and changing it to int main, didnt work.
I would try creating a completely new project and pasting this code into it, it looks like it is picking up extra files right now that you don't realize.
What are you using to write code? Visual Studio? (I'm assuming yes because of the LNK2005 error) If you have a project with multiple files in it, you should make sure that main() is not also declared in one of the other files.

EDIT: Say for example you did homework3 in homework3.cpp. You can create calculator.cpp in the same project (probably not desired), but you would have to remove the main() function from homework3.cpp.
Last edited on
Same code as before, I deleted a previous Debug folder and it fixed the main() error... the new bug report is as follows:

1>------ Build started: Project: Calculator, Configuration: Debug Win32 ------
1>Compiling...
1>Calc.cpp
1>c1xx : fatal error C1083: Cannot open source file: '.\Calc.cpp': No such file or directory
1>Build log was saved at "file://c:\C++\Zach Page\C++\Favorite_Number\Debug\BuildLog.htm"
1>Calculator - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Include the iostream library
#include <iostream>
 
//Use the standard namespace
using namespace std;
 
void main ( )
{
   // Declare the variables
   float Favorite_Number;
 
   // Give instructions
   cout << "Try to Guess My Favorite Number!" << endl;
   cin >> Favorite_Number;
   // Get numbers
   
   if (Favorite_Number == 13)

   // Print responce to getting the answer correct
   cout << "Amazing! How did you guess that?!?!" << endl;
 
   system ("PAUSE");
}
Well, the error message is pretty self-explanatory. Your compiler is expecting to find a file Calc.cpp, but it's not there.

Did you delete it from the hard drive?

Does your project still contain a reference to this file despite it being deleted?
Topic archived. No new replies allowed.