0

I know this has been asked a thousand times but I can't fix this simple problem.

This is the code:

#include<iostream> 
using namespace std;

int main()  
(

bool response= 234;
char character= 68;
int integer= 123.456789;
float single_precision_number= 1234.56789;
double double_precision_number= 1234.56789

cout << "response =  " << response << endl;
cout << "character =  " << character << endl;
cout << "integer =  " << integer << endl;
cout << "single_precision_number =  " << single_precision_number << endl;
cout << "double_precision_number =  " << double_precision_number << endl;


return 0;

}

the following error:

(8): warning C4305: 'initializing' : truncation from 'int' to 'bool'

(10): warning C4244: 'initializing' : conversion from 'double' to 'int', possible loss of data

(11): warning C4305: 'initializing' : truncation from 'double' to 'float'.


1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
scohe001
  • 15,110
  • 2
  • 31
  • 51
  • First of all, there's only one error message, the other are warnings. Warnings are not fatal during compilation, but usually indicates something weird you're doing that might lead to [*undefined behavior*](http://en.wikipedia.org/wiki/Undefined_behavior) and possible weird behavior (including crashes. Pay attention to the warnings, and solve them! The only error you get is not a compilation error but a *linker* error. The error in question is that a symbol the linker tried to find in any object file or library couldn't be found. – Some programmer dude Jul 25 '14 at 22:32
  • As for *why* you get that linker error, it's most likely because you created your project as a WIN32 application, and not a console application. WIN32 applications start their execution not in `main` but in a function called [`WinMain`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms633559%28v=vs.85%29.aspx). – Some programmer dude Jul 25 '14 at 22:33
  • @sehe I think the more correct dupe actually is [undefined reference to `WinMain@16'](http://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16). – πάντα ῥεῖ Jul 25 '14 at 22:36
  • @πάνταῥεῖ I thought so too. :) – Some programmer dude Jul 25 '14 at 22:37
  • @JoachimPileborg At least I added a link for it to my answer in the wrongly marked dupe now ;) ... – πάντα ῥεῖ Jul 25 '14 at 22:38
  • **@Downvoters** Why? The question is clearly asked, giving all(most) the necessary information and code sample. It's a dupe, not more, no less. I've seen a lot worse questions that have been asked here. – πάντα ῥεῖ Jul 25 '14 at 22:46
  • The error might occur due to the way you wrote your main function. Try adding input argument in your main function like: int main(int argc, char** argv){// ...do something... //} or int main(const int &){// ...do something... //} the main function reads in argument, which you did not include. – Juniar Jul 26 '14 at 03:56

0 Answers0