I am a beginner in C++ and I am getting an error doing my project and its driving me nuts! There may be several errors in this code, I am sure there are, but I can not get VS to compile past this error to tell me whats wrong in the first place.
The Error: "error LNK1561: entry point must be defined" (followed by a C:\ path to my project
My system:
Using Visual Studio 2013 Version 12.0.30501.00 Update 2
.NET Framework Version 4.5.50938
Windows 7
Code:
/*
9/28/2014
Intro to Programming
Project 2: BMI Calculator
This project will calculate body mass index of subject based on entries provided.
*/
#include <iostream> // For basic library
#include <iomanip> // For setprecision command
#include <cmath> // For advanced math functions
#include <string> // For string usage
using namespace std; // Standard namespace
int main() // Initializing main function
{
string getName = ""; //Used for getting subject name
double getWeight = ""; // Used for getting subject weight
int getHeight = ""; // Used for getting subject height
double displayBmi = ""; // Used for displaying BMI
//Get name
cout << "Enter your name: ";
cin >> getName;
//Get weight in pounds
cout << "Enter your weight in pounds to one decimal point: ";
cin >> getWeight;
//Get height in inches
cout << "Enter your height in inches: ";
cin >> getHeight;
//calculate and display BMI (Body mass index) display to one decimal place (setprecision(3))
cout << "Your Body Mass Index (BMI) is: " << displayBmi setprecision(3);
cout << (703 * getWeight / pow(getWeight, 2.0))
//Display weight category in if/else 18.5 to 25
if(displayBmi <= 18.5)
{
// Output underweight
cout << "You are currently underweight, eat more!\n";
}
if(displayBmi >= 25)
{
// Output overweight.
cout << "You are currently overweight. It may be time to start an excercise regiment in conjunction with a good diet!\n";
}
else
{
// Output optimal.
cout << "You are currently in the optimal BMI category, great job!\n";
return 0;
}
For this project, I can only use chapters 1-4 of my book, so I don't know what code tags are yet, so can not use those.
I am not sure about your question about how I set it up. I basically had to set up a psuedocode, and then code around it to find the BMI using a formula given to me (BMI = 703*weight / height^2)
I mean when you opened your Visual Studio IDE, how did you create the project that you are compiling? The error seems to suggest the file you've posted isn't included in the project and so isn't being used.
/*
9/28/2014
Intro to Programming
Project 2: BMI Calculator
This project will calculate body mass index of subject based on entries provided.
*/
#include <iostream> // For basic library
#include <iomanip> // For setprecision command
#include <cmath> // For advanced math functions
#include <string> // For string usage
usingnamespace std; // Standard namespace
int main() // Initializing main function
{
string getName = ""; //Used for getting subject name
double getWeight = ""; // Used for getting subject weight
int getHeight = ""; // Used for getting subject height
double displayBmi = ""; // Used for displaying BMI
//Get name
cout << "Enter your name: ";
cin >> getName;
//Get weight in pounds
cout << "Enter your weight in pounds to one decimal point: ";
cin >> getWeight;
//Get height in inches
cout << "Enter your height in inches: ";
cin >> getHeight;
//calculate and display BMI (Body mass index) display to one decimal place (setprecision(3))
cout << "Your Body Mass Index (BMI) is: " << displayBmi setprecision(3);
cout << (703 * getWeight / pow(getWeight, 2.0))
//Display weight category in if/else 18.5 to 25
if (displayBmi <= 18.5)
{
// Output underweight
cout << "You are currently underweight, eat more!\n";
}
if (displayBmi >= 25)
{
// Output overweight.
cout << "You are currently overweight. It may be time to start an excercise regiment in conjunction with a good diet!\n";
}
else
{
// Output optimal.
cout << "You are currently in the optimal BMI category, great job!\n";
return 0;
}
}
These variables would be initialized with numbers, not empty strings.
1 2 3
double getWeight = ""; // Used for getting subject weight
int getHeight = ""; // Used for getting subject height
double displayBmi = ""; // Used for displaying BMI
line 35 - missing a <<, and I think you want setprecision before displayBmi
line 36 missing ;
Edit: I don't see that you assign a calculated value to displayBmi
Line 36 is supposed to be the calculated value for displayBmi, thats my only other problem I believe is the calculation there, should it be something like
as a seperate line? Also, if my original equation is BMI = 703*weight / height^2 (the ^ being text notation for squared) would the correct cpp be as above?
Ok, fixed the lines above and initialized them to just 0 (i hope that will be right to get the number input? The program is now compiling in Win32 environment with no errors, but still not compiling in blank project, with same error.
and last question (as long as formula is written correctly, what can i put in to hold the window open until key is pressed after final formula is displayed? cin.get(); is not working
/* Anthony Morrison
9/28/2014
Intro to Programming
Project 2: BMI Calculator
This project will calculate body mass index of subject based on entries provided.
*/
#include <iostream> // For basic library
#include <iomanip> // For setprecision command
#include <cmath> // For advanced math functions
#include <string> // For string usage
usingnamespace std; // Standard namespace
int main()
{
string getName = ""; //Used for getting subject name
double getWeight = 0; // Used for getting subject weight
int getHeight = 0; // Used for getting subject height
double displayBmi = 0; // Used for displaying BMI
//Get name
cout << "Enter your name: ";
cin >> getName;
//Get weight in pounds
cout << "Enter your weight in pounds to one decimal point: ";
cin >> getWeight;
//Get height in inches
cout << "Enter your height in inches: ";
cin >> getHeight;
//calculate and display BMI (Body mass index) display to one decimal place (setprecision(3))
cout << "Your Body Mass Index (BMI) is: " << setprecision(3) << displayBmi;
cout << (703 * getWeight / pow(getWeight, 2.0));
//Display weight category in if/else 18.5 to 25
if (displayBmi <= 18.5)
{
// Output underweight
cout << "You are currently underweight, eat more!\n";
}
if (displayBmi >= 25)
{
// Output overweight.
cout << "You are currently overweight. It may be time to start an excercise regiment in conjunction with a good diet!\n";
}
else
{
// Output optimal.
cout << "You are currently in the optimal BMI category, great job!\n";
}
cin.get();
}
ok, so obviously my equation is wrong because I ended up getting a BMI of 02.46 when i dont believe thats possible. So, any help on the equation please?
/*
9/28/2014
Intro to Programming
Project 2: BMI Calculator
This project will calculate body mass index of subject based on entries provided.
*/
#include <iostream> /// For basic library
#include <iomanip> /// For setprecision() command
#include <cmath> /// For advanced math functions
#include <string> /// For string usage
usingnamespace std; /// Standard namespace std
int main() /// Initializing main function
{
string getName = ""; ///Used for getting subject name
double getWeight = 0; /// Used for getting subject weight
int getHeight = 0; /// Used for getting subject height
double displayBmi = 0; /// Used for displaying BMI
///Get name
cout << "Enter your name: ";
cin >> getName;
///Get weight in pounds
cout << "Enter your weight in pounds to one decimal point: ";
cin >> getWeight;
///Get height in inches
cout << "Enter your height in inches: ";
cin >> getHeight;
///calculate and display BMI (Body mass index) display to one decimal place (setprecision(3))
if (displayBmi<1){
setprecision(3);
}
cout <<endl<<getName<<", your Body Mass Index (BMI) is: " <<displayBmi;
cout << (703 * getWeight / pow(getHeight, 2.0));
///Display weight category in if/else 18.5 to 25
if (displayBmi <= 18.5){
/// Output underweight
cout <<endl<<getName<<", you are currently underweight, eat more!\n";
}elseif (displayBmi >= 25){
/// Output overweight.
cout <<endl<<getName<<", you are currently overweight. It may be time to start an exercise regiment in conjunction with a good diet!\n";
}else{
/// Output optimal.
cout <<endl<<getName<<", you are currently in the optimal BMI category, great job!\n";}
return 0;
}