4

What have I screwed up here? There can be no hard coded values in the code which is why all my prompts are constants. We also have to call a user defined function to verify input.

Im getting the following error when I compile -- undefined reference to WinMain, [Error] Id returned 1 exit status I'm using Dev C++ as an IDE

#include <iostream> //for I/O #include <iomanip> //for formatting output using namespace std; const string PROGRAM_DESCRIPTION = "Program will calculate the amount " "accumulated every month you save, \nuntil you reach your goal. "; const string ENTER_DOLLAR_AMOUNT_MONTHLY = "Enter the dollar amount to be " "saved each month: "; int main() { double dollarSavedPerMonth; //displays program description cout << PROGRAM_DESCRIPTION << endl << endl; //Prompts user to enter dollar amount to be saved monthly, will validate //input by calling VerifyDollar dollarSavedPerMonth = VerifyDollar(ENTER_DOLLAR_AMOUNT_MONTHLY); cout << endl; return 0; } double VerifyDollar (string Prompt) { const string INVALID_DOLLAR_AMOUNT = "Invalid amount, re-enter monthly " "savings amount."; double dollarSaved; cout << Prompt; cin >> dollarSaved; while (dollarSaved < 5 || dollarSaved > 5000) { cout << INVALID_DOLLAR_AMOUNT; cout << endl; cout << Prompt; cin >> dollarSaved; } return dollarSaved; } 
4
  • 2
    Note: When you use std::string, include the <string> header. In any case, this should not even get to the linking part because you use VerifyDollar before declaring it, so how you have a linker error is beyond me. Commented Feb 8, 2014 at 23:11
  • Are you using an multi-target IDE? I'd guess the project settings are wrong. Commented Feb 8, 2014 at 23:14
  • added prototype since function is defined after main Commented Feb 8, 2014 at 23:21
  • Does this answer your question? undefined reference to `WinMain@16' Commented Jul 26, 2023 at 8:43

1 Answer 1

7

You do indeed lack a WinMain() function anywhere in that code.

If memory serves me well, WinMain() is the entry point for a Win32 GUI app. I am assuming your IDE asked you for a "project type" of some sort, and you asked for a Windows app instead of a Console one.

Under that assumption, something in your project is configured to call WinMain(), which you did not define, hence the linker error.

Sign up to request clarification or add additional context in comments.

2 Comments

when I'm able to choose a project I get a bunch of options...Basic (windows app, console app, static library, dll, empty project) Multimedia (direct 3D, Open GL) Win 32 (file editor, mdi editor, animation example) Console (hello world, input loop, jackpot, open MP) I've always selected hello world, I must have just selected something else, after copying the code and re selecting the project it works
You don't need a WinMain even with a Windows subsystem (and indeed I get along fine without all the time). See stackoverflow.com/questions/5259714/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.