I have seen posts about this problem before, and tried everything within them.
This code is for my Freshmen (9th grade) free class, and I am making a simple calculator with if/then statements. I have my first adding portion assembled, but when I try to compile/run it doesn't work.
#include <iostream.h>
usingnamespace std;
int add ( int x, int y )
{
{
int typeofmath;
cout<<"(1)Add/(2)Subtract/(3)Multiply/(4)Divide: ";
cin>> typeofmath;
cin.ignore();
if ( typeofmath == 1 )
{ int x;
int y;
cout<<"Please enter the two numbers you want added: "; //Goal: Figure out how the WinMain@16 error works/is/fix!!!
cin>> x >> y;
cin.ignore();
cout<<"Your answer is "<< add ( x, y );
cin.get();
}
int add ( int x, int y );
{
return x + y;
}
}
}
Also, I have tried adding int main() and iostream.h
It looks like you accidentally made a windows application project, rather than a console project. This is why it is looking for the windows entry point 'WinMain', rather than the console entry point 'main'.
I suggest you create a new project, being careful to select "Console Application", and then copy the source code over from the old project to the new one.
PS: What is your IDE? You should really be #including "iostream" rather than "iostream.h" these days. ;)
PPS: If I were you I would check your code - there seem to be a few stray curly braces.
Good point - the configuration wizard is annoying ;)
I don't think Visual Studio has an "iostream.h" header file though, so I guess the OP has a different IDE. But maybe I'm wrong...
I love the configuration wizard! hehe. I hated it when I didn't understand the precompiled header, though. :-S Not that I FULLY understand now. :-P
But true about the empty project. In Visual Studio, select Win32 Project, then in the Settings page select Empty Project. This way you'll be free of the precomppiled header.
I assumed a precompiled header was just a header file that got compiled before being included to speed up compile times.
And yes, it does have iostream, sstream, etc.
Lol, I know it has the standard header files :P. What I was saying is that my version of MSVCE 2010 definitely doesn't have "iostream.h", i.e. the old style header file with the '.h' extension.
Alright, I have re-done the code, and Ill include a bit more information this time.
I removed the .h, as it was useless. I tried using a different compiler (From the Code :: Blocks to DevC++) and both got similar errors. I have a feeling that it has to do with the int add (int x, int y) line of code, and the missing int main().
I am using the Code :: Blocks Compiler currently.
Also, creating a blank project did not fix the error, just caused confusion, as I could not create anything within the project.
Also, what is an IDE?
Included is the code, with a few of the stray curly braces removed :P
#include <iostream>
usingnamespace std;
int add ( int x, int y);
{
{
int typeofmath;
cout<<"(1)Add/(2)Subtract/(3)Multiply/(4)Divide: ";
cin>> typeofmath;
cin.ignore();
if ( typeofmath == 1 )
{ int x;
int y;
cout<<"Please enter the two numbers you want added: ";
cin>> x >> y;
cin.ignore();
cout<<"Your answer is "<< add ( x, y );
cin.get();
}
int add ( int x, int y );
{
return x + y;
}
}
}
It stands for Integrated Development Environment. It is a piece of software which combines an editor (usually with syntax highlighting and code completion) with a compiler and linker, and often many other plugins for various purposes.
I am using the Code :: Blocks Compiler currently.
In fact, Code::Blocks is an IDE. The compiler it uses by default is called MinGW. The same is true for Dev C++, which, I stress, you should no longer be using as it is abandonware (unless you mean wxDev C++).
missing int main().
Without an entry point of some kind (int main for console applications, INT WinMain for windows applications etc.), you cannot create an executable application. What exactly are you trying to do?
Sorry for the long reply time, the schools network has been down and I could not get home access.
I am trying to build a calculator with if/then statements. There are easier ways to do it, but with the little amount I have been taught, I figured this would be a challenging process :P
This is the first chunk, the adding portion. When I tried to compile it, I got the error.
So what can I do to fix the error? I need to declare a variable, such as int main or winmain, but I also need to include the x and y integers.
I stress, you should no longer be using as it is abandonware
I have uninstalled it and am back to Code::Blocks. I like the interface more too.
Also, I am on an age-old XP, not sure if that affects anything much.
If you want to compile your code to a console program which runs, i.e. a .exe file, then you must have a main function. There is no other option. This is the console entry point. Without it you cannot define with which code your (console) program starts.
If all your code is in other functions, then just call them from main.
If you want these functions to be available to you when you write future programs, then you will need to compile your code into a static or dynamic library. These do not need an entry point.