Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
615 views
in Technique[技术] by (71.8m points)

c++ - undefined reference to WinMain, [Error] Id returned 1 exit status

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, 
until 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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...