我尝试构建时收到以下错误:
1> MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1> G:\CMPSC 101\Projects\Project 2\Project2\Debug\Project2.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
这里是我在cpp文件中编写的代码:
// Source file name: Project2.cpp
// This program determines a user's target heart rate and body mass index
// when the user's age, height, and weight are input
// Date written: 27 Feb 2014
// Date modified: 3 Mar 2014
#include <iostream>
using std::cout;
using std::endl;
#include <iostream>
using namespace std;
int main()
{
//age is the input variable from user, target_heart_rate is output after calculation
int age, target_heart_rate;
int weight;
int height, bmi;
//Display Program Introduction and Credits
cout << "Happy Valley Health Club" << endl;
cout << "Target Heart Rate Calculator" << endl;
cout << "Written by Paul D. Wagaman" << endl;
//Display Target Heart Rate Formula
cout << "Your Target Heart Rate is 70% of (220 - your age)" << endl;
//Prompt User to enter their age as a whole number
cout << "Please enter your age as a whole number" << endl;
//User inputs their age
cin >> age;
//Display Body Mass Index Formula
cout << "BMI (kg/m2) = [Weight (lbs) x 703] / Height (in2)" << endl;
//Prompt User to enter their age as a whole number
cout << "Please enter your weight (in pounds) as a whole number" << endl;
//User inputs their age
cin >> weight;
//Prompt User to enter their age as a whole number
cout << "Please enter your height (in inches) as a whole number" << endl;
//User inputs their age
cin >> height;
//Perform target heart rate calculation
//70% of ( 220 - age )
target_heart_rate = ((70 * (220-age))/100);
//Perform BMI calculation
//70% of ( 220 - age )
bmi = (weight * 703) / (height * height);
//Display user’s target heart rate
cout << "70%" << " ( " << "220" << " - " << age << " ) " << " = " << target_heart_rate << endl;
cout << "Your target heart rate is " << target_heart_rate << " beats per minute." << endl;
//Display user’s body mass index
cout << "Your BMI formula = (" << weight << "pounds" << " x " << "703)" << " / " << " ( " << height << " squared." << endl;
cout << "Your individual Body Mass Index is " << bmi << endl;
//Display “Thank You” message
cout << "Thank you for choosing Happy Valley Health Club – We care about YOUR health!";
return 0;
}
有人能说清楚我做错了吗?
答案 0 :(得分:1)
自从我编写一个Windows应用程序以来,很长一段时间,但这感觉就像你正在创建一个Windows应用程序而不是一个控制台应用程序,因此你的代码中应该有一个WinMain(http://msdn.microsoft.com/en-us/library/windows/desktop/ms633559%28v=vs.85%29.aspx)......
答案 1 :(得分:1)
您似乎选择了错误的项目类型。 WinMain可以在Windows程序中找到,但您显示的代码是用于控制台应用程序。如果您在Visual Studio中执行此操作,则可能必须将项目重新创建为控制台应用程序,而不是Windows应用程序。