The objective for today's lab is to investigate the differences between
sequential and Conditional programming.
- Paste the following code into Eclipse or cpp.sh
#include <iostream>
using namespace std;
// Programmer:
// This program prompts the user for a non-zero length and
// width of the house and then computes the perimeter of the house
//
//Variable Dictionary
//length_of_house input by the user as a double length
//width_of_house input by the user as a double width
//perimeter perimeter of the house, calculated by the programmer
//************************************************************************
int main()
{
double length_of_house, width_of_house;
double perimeter;
//Shouldn't we ask the user to input???
cin >> width_of_house;
cin >> length_of_house;
//What if the user enters 0???
perimeter = 2*(length_of_house+width_of_house);
cout << "The perimeter is \n" << perimeter;
//Shouldn't we also print out the input values??
return 0;
}
- Save the code somewhere
- Run the code
- Update the comments
- Place a cout at the end of the code to print your name
- Put couts in the code to prompt the user for the length and width
- Put couts in the code to print out the input values for length and width
- Sample
- House length cannot be less than 24 nor bigger than 75
- Use conditionals to verify the length and if invalid, output
an error message and do not continue the program.
- Length compared to 24
- Improved Length compared to 24
- Length compared to 24 and 75
- Improved Length comparison for 24 and 75
- House width cannot be less than 36 nor bigger than 100
- Use conditionals to verify the width and if invalid, output
an error message and do not continue the program.