WorkSheet #2 - Focusing on Conditionals (if/else) 1) Create a new project and cpp file in your environment. You should be able to do this quite easily at this point without referring to notes. If you're still struggling there, it means you need to practice much more to catch up. Remember to compile often and to test in pieces. 2) This work sheet will focus on using if and if/else expressions. Using the variables from the first worksheet (they will be repeated here) write if expressions to make sure that values were entered correctly. If they were not correct, feel free to fix them automatically for now. (Later we'll learn how to bug the user to give us a proper value). Attributes: name, age, height, weight, shoe size, employment status, number of courses taken, number of credit hours taken, current GPA Example: for weight. We're going to assume that weights are in pounds and that valid weights are in the range 0 pounds to 4000 pounds for a human. We've chosen weights to be stored as integers, although we could consider float and double to be valid choices if we wanted to allow weights with decimal places. int weight; cout << "Please enter your weight in pounds: "; cin >> weight; cout << "You have entered " << weight << " pounds." << endl; if(weight < 0) { //then this weight is invalid cout << "Weight is below 0. IMPOSSIBLE! Weight is now 0." << endl; weight = 0; //I've "automatically" corrected this value. } if(weight > 4000) { //then this weight is still invalid! cout << "Weight is above 4000. Weight is now 4000." << endl; weight = 4000; } cout << "Weight is now " << weight << " pounds." << endl; //there are also ways to string ifs together and use AND/OR boolean logic 3) When you've satisfied yourself that all values are being handled with errors, make a new check at the end of your code relating to cin.fail(). If you get to the end of your code and cin has failed, then it means some of the variables were not read in by cin. It would look something like this: if( cin.fail() ) { cout << "Input failed. Remaining output is erroneous" << endl; } 4) Lastly, we make a bunch of cout statements to turn this assignment into a story. After I entered some information the final story might say the following: Doc is using this program. Doc is 12 years old, 37 pounds, and stands only 23 inches tall. Doc wears a size 2 shoe. Doc has no employment, 0 courses taken, 0 credit hours taken and a 4.0 GPA. Way to go Doc. ----- Preparing for the final project! Last time you were told that your final project would have some sample variables and values. That list is repeated below. To prepare for the final project, you can make several tests for proper input. Total mass, fuel mass and ISP can never be below 0. Also, total mass must be larger than fuel mass. Write some if statements to protect these values such that they never get to the bottom of the code in an erroneous state. Write down any assumptions or decisions you make when you complete this process. -craft name ex: Challenger -total mass ex: 1995806.42 -fuel mass ex: 1671487.88 -ISP ex: 180.3 -gravity a constant value at 9.80665