WorkSheet #3 - Focusing on Loops (while loops!) 1) Creating a new project and adding a cpp should be easy now! Remember to compile often and to test in pieces. 2) This worksheet will focus on using the while loop. Using the variables from the first worksheet (they will be repeated here) write loop expressions to make sure that values were entered correctly and if not, force the user to enter them again. 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; while(weight < 0 || weight > 4000) { cout << "Error: You have entered " << weight << " pounds." << endl; cout << "Input weight in pounds: "; cin >> weight; } cout << "Weight is now " << weight << " pounds." << endl; 3) 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. 4) When you've satisfied yourself that all values are being handled with errors, write a loop around all the input that allows the user to go through the process again. Something like the following: char goAgain = 'y'; while( goAgain == 'y' ){ //get all the variable values //output the story cout << "Would you like to repeat this entry? (y/n): "; cin >> goAgain; } Extra: try doing this with a string for yes/no or with an integer for 0 to quit 1 to continue 5) Extra: Going beyond. After reading in a float or an int, also make sure that cin has not entered a failure state. If it has, clear/ignore and reacquire that variable from the user. 6) To make it even more interesting, keep track of the number of times the user has continued this process. Then, when the user finally says no, give the averages of the numerical values! ----- 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, write loops to get proper values for all input. Protect the input from improper user data entry including cin.fail. Remember, mass, fuel mass and ISP can never be below 0. Also, total mass must be larger than fuel mass. Write down any assumptions or decisions you make when you complete this process. When complete, write a for loop that allows the user to do this entry 3 times. Each time through the loop will end up corresponding to a different stage of a rocket. Lastly, write a while loop to allow the user to do it all again. (So if the user wants to do this again, they will enter all the values three more times). -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