Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using std::cout;
- using std::cin;
- using std::endl;
- const int BMI_CONST=703;
- // modern c++ compilers are mostly read-forward
- //function prototype - I promise I'll define my function later!
- double calcBmi(double j=0, double k=0); //- can't specify default args twice!
- // double calcBmi(double j, double k);
- // double calcBmi(double,double);
- //more than one fx prototype will work unforuntaely
- //we ONLY have to do function prototypes when the function proceeds main instead of preceeding it!
- void foo() {
- cout << "I'm before!";
- }
- int main(){ //command line arguments
- foo();
- // BMI_CONST = BMI_CONST + 1; => ++ // no can do with a constant!
- int i;
- cout << i; //0 because i has not been defined yet!
- i = 9;
- cout<< "Hello World" << std::endl;
- cout<< "Our C++ version is:" << __cplusplus << "\n" << endl; // we covered how this varies with stdC++ flag
- cout << "Enter weight and height" << endl;
- double height, weight;
- cin >> height >> weight;
- // type identifier = expression
- // any operation to the right of the assignment operator (==) is considered an expression!
- //TODO: discuss literal default values
- // "matt" -> char* arr
- double blah = 1 + 2 ; //this is an expression!
- double bmi = calcBmi(height, weight); //make a copy of the data of our local variables and pass that into the function!
- //position based arguments.
- if (int bmi2 = calcBmi(height, weight); bmi2 < 2000) {
- cout << "You're skinny!";
- } else cout << "You're overweight!";
- cout << "Your BMI is: " << bmi << endl;
- cout << "Type cast " << (int) (bmi) << endl;
- unsigned char uc = 149;
- signed char sc = (signed char) (uc);
- //truncation is the act of reducing bits which results in a loss of precision
- // 8bits unsigned => 8bits
- cout << (int) (sc); //numerical overflow! go from 8 bit signed char to 32 bit integer
- //TODO
- switch((int) (calcBmi(height,weight))){
- }
- //TODO: default vals!
- //default arguments allow for magic!
- cout << "Default args magic!: " << calcBmi() << endl;
- return 0;
- }
- //this is called copy by value!
- double calcBmi(double h, double w) { //doesn't matter if I name the params the same as the name of the variables passed in
- // h = 93209; // the value in main() does NOT change!
- return (BMI_CONST*w)/ (h);
- }
- //Formula: 703 x weight (lbs) / [height (in)]2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement