Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (kikuo):

Check for logic errors?

OpenStudy (kikuo):

//Ashton Dreiling //BMI Exercise #include <iostream> #include <stdlib.h> using namespace std; //module prototype void calculatesBmi(double &BMI,double weight, double height); //Global constants const int NUMBER = 702; const double NUMBERFORBMIRANGE = 18.5; const int SECONDNUMBERFORBMIRANGE = 25; int main() { //some variables double weight; double height; double BMI; cout << "Hello, today we are going to be calculating your BMI" << endl; cout << "Please type in your weight in pounds" << endl; cin >> weight; cout << "You typed in " << weight << endl; cout << "Please type in your height in inches." << endl; cin >> height; cout << "You typed in " << height << endl; cout << "Please give us a second to calculate your BMI." << endl; calculatesBmi(BMI,weight,height); //pass variables to calculatesBmi module cout << "Your BMI is " << BMI << endl; //determine whether whether the user is underweight, overweight, or optimal if ( (BMI > NUMBERFORBMIRANGE) && (BMI < SECONDNUMBERFORBMIRANGE)) cout << "You are in optimal range!" << endl; else { if (BMI<NUMBERFORBMIRANGE) cout << "You are underweight. Are you okay? Eat better!" << endl; else { if (BMI>SECONDNUMBERFORBMIRANGE) cout << "It's okay to like your body, but stay healthy, too! Exercise, it's good for you!" << endl; } } system("Pause"); return 0; }//end main void calculatesBmi(double &BMI,double weight, double height) { //calculating BMI BMI = weight / (height * height) * NUMBER; }//end calculatesBmi @Sachintha Did I do everything correctly?

OpenStudy (sachintha):

Seems ok. Btw, it is good to use proper syntax. if(condition) { //some code } else { //some code }

OpenStudy (kikuo):

I don't know what you mean by that? If the syntax wasn't proper, it wouldn't compile since syntax controls how the compiler turns it into machinery code. Is there something specific you don't like?

OpenStudy (sachintha):

This is the proper syntax of a if statement. But it does compile properly without them under certain circumstances. http://www.tutorialspoint.com/cplusplus/cpp_if_else_statement.htm PS. This site is really good to learn c++ with proper documentation.

OpenStudy (kikuo):

Ah I see : )

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!