Please help hint what to do. I have no idea how to fix these mistakes. http://prntscr.com/bfp0d0 http://prntscr.com/bfp0fm
@Sachintha
Remove void keyword and try.
http://prntscr.com/bfp98f This is what he said about passing reference parameters to modules
You need to add the ampersand to the parameter name and not before the data type.
Hm, I don't quite understand.
Can you show me in my code?
\(\sf \color{blue}{void}~calculatesBmi(double~\color{red}{\&}weight, double~\color{red}{\&}height);\)
Remember to close it!
Let me just give you the list of all the errors I have right now and we can work through them haha http://prntscr.com/bfpc7y http://prntscr.com/bfpcdt http://prntscr.com/bfpcfi
First check every line whether you have closed it properly. Most of the errors are due to missing semi-colons.
Fixed em. Down to five. : )
Const should be const. Make it all simple.
Down to four : )
Add a screenshot of the errors and edited code.
http://prntscr.com/bfpf3n http://prntscr.com/bfpf6d http://prntscr.com/bfpf7v Five actually
Yet you haven't closed everything properly. You have missed the variables and those inside the BMI function.
I haven't? But I put semicolons in the places that weren't working, and they worked? Am I misunderstanding what you mean by close? @Sachintha
But you haven't put semicolons after the variables height, weight inside main() and those inside the BMI function.
Try adding the BMI variable inside main()
Hm, that didn't work. @Sachintha
Show me how you added it.
Why are you adding the void keyword?
double is a data type which is why I added it
No I meant why did you add the void keyword in-front of the calculatesBmi function? Did you sir say so?
Yes.
Add this code in line 31 and try. Not sure whether it would return anything. BIM = calculatesBmi( weight, height);
It worked! Can you explain why it did?
Oh wait it says its an error now wth lol
What is the error?
Try removing void keyword from the function. Also remove line 35.
Wait I will try running it on a online compiler.
//Ashton Dreiling //6/9:00 PM/2016 //BMI exercise #include <iostream> #include <stdlib.h> using namespace std; //module prototype void calculatesBmi(double &weight, double &height); //Global constant const double KILOGRAM = 0.453592; int main() { //some variables double BMI; double weight; double height; cout << "Hello, today we are going to be calculating your BMI" << endl; cout << "Please type in your weight" << endl; cin >> weight; cout << "You typed in " << weight << endl; cout << "Please type in your height" << endl; cin >> height; cout << "You typed in " << height << endl; cout << "Please give us a second to calculate your BMI." << endl; BMI = calculatesBmi( weight, height); //pass variables to calculatesBmi module cout << "Your BMI is " << BMI << endl; system("Pause"); return 0; }//end main void calculatesBmi(double height, double weight) { //calculating BMI double BMI; BMI = weight / height * height; }//end calculatesBmi
Do you have a note about the use of void given by your sir?
-for now the headers for all the C++ functions that you will write begin with the key word void -following this you write the name of the function and a set of parentheses -function header never ends with a semicolon
/* This is a test for loading the MaxDensity curves Ray Warren 22 May 2015 */ #include <iostream> #include <cstring> using namespace std; //module prototypes void noReferenceParameters(int anInt, double aDouble, string aString); void withReferenceParameters(int &anInt, double &aDouble, string &aString); int main() { //some variables int myInt = 1; double myDouble = 1.0; string myString = "Hello"; // output the variables cout << "The variable values in main(): " << endl; cout << " myInt: " << myInt << " myDouble: " << myDouble << " myString: " << myString << endl; // call the no reference parameter module noReferenceParameters(myInt, myDouble, myString); // output the variables cout << "The variable values in main(): " << endl; cout << " myInt: " << myInt << " myDouble: " << myDouble << " myString: " << myString << endl; cout << "They remain unchanged in main()" << endl; // call the no reference parameter module withReferenceParameters(myInt, myDouble, myString); // output the variables cout << "The variable values in main(): " << endl; cout << " myInt: " << myInt << " myDouble: " << myDouble << " myString: " << myString << endl; cout << "They are now changed in main()" << endl; } //end main() void noReferenceParameters(int anInt, double aDouble, string aString) { anInt = anInt * 2; // double it aDouble = aDouble * 2; // double it aString = aString + " World!"; // output the variables cout << endl; // output a blank line // "\t" is the tab character cout << "\tThe variable values in noReferenceParameters(): " << endl; cout << "\t myInt: " << anInt << " myDouble: " << aDouble << " myString: " << aString << endl; cout << endl; // output a blank line } //end noReferenceParameters() void withReferenceParameters(int &anInt, double &aDouble, string &aString) { anInt = anInt * 2; // double it aDouble = aDouble * 2; // double it aString = aString + " World!"; // output the variables cout << endl; // output a blank line // "\t" is the tab character cout << "\tThe variable values in withReferenceParameters(): " << endl; cout << "\t myInt: " << anInt << " myDouble: " << aDouble << " myString: " << aString << endl; cout << endl; // output a blank line } //end withReferenceParameters()
Whew!! It worked. ^_^ #include <iostream> #include <stdlib.h> using namespace std; //module prototype void calculatesBmi(double &weight, double &height); //Global constant const double KILOGRAM = 0.453592; 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" << endl; cin >> weight; cout << "You typed in " << weight << endl; cout << "Please type in your height" << endl; cin >> height; cout << "You typed in " << height << endl; cout << "Please give us a second to calculate your BMI." << endl; calculatesBmi(weight, height); //pass variables to calculatesBmi module cout << "Your BMI is " << BMI << endl; system("Pause"); return 0; }//end main void calculatesBmi(double &weight, double &height) { //calculating BMI double BMI; BMI = weight / (height * height); cout << BMI; }//end calculatesBmi
What did you change?
I added a line to output BMI inside the function and fixed some typos.
This one works. But I had to pass another reference parameter. #include <iostream> #include <stdlib.h> using namespace std; //module prototype void calculatesBmi(double &BMI,double &weight, double &height); //Global constant const double KILOGRAM = 0.453592; 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" << endl; cin >> weight; cout << "You typed in " << weight << endl; cout << "Please type in your height" << 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; system("Pause"); return 0; }//end main void calculatesBmi(double &BMI,double &weight, double &height) { //calculating BMI BMI = weight / (height * height); }//end calculatesBmi
Join our real-time social learning platform and learn together with your friends!