BMI Calculator Help.

Hello i am trying to code a BMI calculator.

This isnt mine i just found on the internet.

The code 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
//BMI Calculator
//Created by Rahul Kucheria
//Oct 29th, 2011

#include<iostream>
#include<iomanip>
#include<math.h>

using namespace std;

int main()

{
    unsigned int weight;
    unsigned int height;
    float bmi;
    char response;
    
    do 
    {
    cout<<"*****************************\n";
    cout<<"Please enter your weight (lbs): ";
    cin>>weight;
    cout<<"Please enter your height (inches): ";
    cin>>height;
    bmi = (weight/ pow(height,2))*703;
    cout<<"\n";
    cout<<fixed<<showpoint<<setprecision(2);
    cout<<"Your BMI is "<<bmi<<endl;
    
    if (bmi < 18.5)
       {  
       cout<<"You are underweight!"<<endl;
       cout<<"Eat more!!"<<endl;
       }
       else if (bmi >= 18.5 && bmi <25)   
       cout<<"You are normal!"<<endl;
       else if (bmi >= 25 )
       cout<<"You are overweight!"<<endl;
       else
       cin.get();
    
       cin.get();
       cout<<endl;
       
       cout<<"Would you like to enter the information again? ";
       cin>>response;
    }
   while (response == 'Y' || response == 'y' );
    
return 0;
    
}



I am using Visual c++ 2010 as my compiler.
I am a complete noob and when i try to debug it, i get the following errors


1>------ Build started: Project: as, Configuration: Debug Win32 ------
1> as.cpp
1>c:\users\rahul\desktop\documents\visual studio 2010\projects\as\as\as.cpp(26): error C2668: 'pow' : ambiguous call to overloaded function
1> c:\program files\microsoft visual studio 10.0\vc\include\math.h(583): could be 'long double pow(long double,int)'
1> c:\program files\microsoft visual studio 10.0\vc\include\math.h(535): or 'float pow(float,int)'
1> c:\program files\microsoft visual studio 10.0\vc\include\math.h(497): or 'double pow(double,int)'
1> while trying to match the argument list '(unsigned int, int)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Can anyone help me out please.

Thanks a lot

It works perfectly for me. I use dev cpp. I downloded that program you use. But it is a complete garbage for noob like us.
I think the problem may be the types of the arguments that you are using in the function "pow" on line 26. I think pow takes two "double" arguments. Try changing line 15 to:

double height;

and line 26 to:

bmi = (weight/ pow(height,2.0))*703;//notice the "2.0" instead of "2"

If this doesn't fix it then I don't know what the problem is.
@rahulkucheria

This now compiles in Visual C++ 2008 Express Edition. I mainly just made weight and height as float, like the variable bmi. And I set it to check toupper(response..), so you need only the capital Y. Added a goodbye message if you press 'n' or anything else, for that matter.
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
// BMI.cpp : Defines the entry point for the console application.
//BMI Calculator
//Created by Rahul Kucheria
//Oct 29th, 2011

#include "stdafx.h"
#include<iostream>
#include<iomanip>
#include<math.h>

using namespace std;

int main()

{
    float weight;
    float height;
    float bmi;
    char response;
    
    do 
    {
    cout << "*****************************\n";
    cout << "Please enter your weight (lbs): ";
    cin >> weight;
    cout << "Please enter your height (inches): ";
    cin >> height;
    bmi = (weight / pow(height,2)) *703;
    cout<<"\n";
    cout << fixed << showpoint << setprecision(2);
    cout<<"Your BMI is " << bmi << endl;
    
    if (bmi < 18.5)
       {  
       cout << "You are underweight!" << endl;
       cout << "Eat more!!" << endl;
       }
       else if (bmi >= 18.5 && bmi <25)   
       cout << "You are normal!"<<endl;
       else if (bmi >= 25 )
       cout << "You are overweight!"<<endl;
       else
       cin.get();
    
       cin.get();
       cout << endl;
       
       cout << "Would you like to enter the information again? ";
       cin >> response;
    }
   while (toupper(response) == 'Y');
   cout << "Okay, see you next time.." << endl; 
return 0;
}
but it worked before for me in dev. idk.
@whitenite1 It works perfectly.
Thanks a lot
Topic archived. No new replies allowed.