Can someone help me with my code please?

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;
}

}
Could you use [code][/code] tags?

It seems the linker can't find the definition of your main function; how did you set up your project?
Last edited on
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)
Code tags are a feature of this forum that highlight your code so it is readable and not plain text.
http://www.cplusplus.com/articles/z13hAqkS/

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.
Open> New Project> Blank Project> New> Source File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* 
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;
	}

}
Last edited on
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
Last edited on
Thanks for the help!

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

displayBmi = (703 * getWeight / pow(getWeight, 2.0);

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?
Also, I am now getting an error on other compilers about line 18 saying something along the lines of replace double with const int
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
Last edited on
The new code that works, but will not hold open after result is displayed is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* 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
using namespace 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?
closed account (48T7M4Gy)
http://en.wikipedia.org/wiki/Body_mass_index

cout << (703 * getWeight / pow(getWeight, 2.0));

should be ...

cout << (703 * getWeight / pow(getHeight, 2.0));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
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 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";
		}else if (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;
}
Last edited on
Topic archived. No new replies allowed.