whats wrong in my code?

#include <iostream>
#include <iomanip>
using namespace std;
double getBMI (int h, int w, double s);


return (w/(h*h));


void output (double b);
cout<<"b"<<b;


int main()
{
int height1, height2, weight1, weight2;
double bim1, bim2;
double scalar = 703.0;
cout<<"Person 1 height:"<<endl;
cin>>height1;
cout<<"Person 2 height:"<<endl;
cin>>height2;
cout<<"Person 1 weight:"<<endl;
cin>>weight1;
cout<<"Person 2 weight:"<<endl;
cin>>weight2;
BMI1= getBMI(height1, weight1, scalar)
;BMI2= getBMI(height2, weight2, scalar)
;output(BMI1);
;output(BMI2);



return 0;
}

C:\Users\KILL\Downloads\bmi.cpp|7|error: expected unqualified-id before 'return'|
C:\Users\KILL\Downloads\bmi.cpp|11|error: expected constructor, destructor, or type conversion before '<<' token|
C:\Users\KILL\Downloads\bmi.cpp||In function 'int main()':|
C:\Users\KILL\Downloads\bmi.cpp|27|error: 'BMI1' was not declared in this scope|
C:\Users\KILL\Downloads\bmi.cpp|28|error: 'BMI2' was not declared in this scope|
||=== Build finished: 4 errors, 0 warnings ===|
Your code for your functions are not in a function body:

1
2
3
4
double getBMI (int h, int w, double s);  // <- this is just a prototype

return (w/(h*h)); // <- this is code existing outside of any function.
  //  That will give you an error. 


You need to give bodies to your function. Do this by getting rid of the semicolon and putting the code body in braces. Just like you do for main():

1
2
3
4
double getBMI (int h, int w, double s)  // <- no semicolon
{  // <- a brace indicating this code is the function body
  return (w/(h*h)); // <- this is now part of the getBMI function body
} // <- getBMI function ends here 


You have a similar problem with your 'output' function

I said you already that the definition of the first function is incorrect.
Why do you duplicate the theme?!
Last edited on
wont let me do that it keeps saying C:\Users\KILL\Downloads
|13|error: expected unqualified-id before '{' token|
You are confused with function prototypes and implementations...

This is a protoype:

int add(int a,int b);

And its implementation/definition is:

1
2
3
4
int add(int a,int b)
{
     return (a+b);
}


Also BMI1 is not declared. check for typos...bim1 not BMI1 !!
also, C++ is a case-sensitive language therefore, BIM1 is not equivalent to bim1

But do you want me to give you the correct code?
Topic archived. No new replies allowed.