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
// Favorite Number program
// Include the iostream library
#include <iostream>
//Use the standard namespace
usingnamespace 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");
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.
// Include the iostream library
#include <iostream>
//Use the standard namespace
usingnamespace 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");
}