diff options
| author | EdwardFine <[email protected]> | 2022-10-06 15:51:28 -0700 |
|---|---|---|
| committer | EdwardFine <[email protected]> | 2022-10-06 15:51:28 -0700 |
| commit | 2443441559750fdb336c6d986f3c3b819079ccf8 (patch) | |
| tree | 0e46ce80db6529b11cfc7cdbab950f5495e8e4d2 | |
| parent | Check aspect ratio and print a message if it's too big. (diff) | |
| download | cst116-lab1-edwardfine-2443441559750fdb336c6d986f3c3b819079ccf8.tar.xz cst116-lab1-edwardfine-2443441559750fdb336c6d986f3c3b819079ccf8.zip | |
Force the user input to be between 1 and 400
| -rw-r--r-- | BlankConsoleLab/CST116-Lab1-Fine.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/BlankConsoleLab/CST116-Lab1-Fine.cpp b/BlankConsoleLab/CST116-Lab1-Fine.cpp index a705e95..cca5be6 100644 --- a/BlankConsoleLab/CST116-Lab1-Fine.cpp +++ b/BlankConsoleLab/CST116-Lab1-Fine.cpp @@ -5,7 +5,7 @@ using namespace std; -int GetArea(int length, int width); +float GetArea(float length, float width); using std::cout; using std::cin; @@ -13,26 +13,33 @@ using std::endl; int main() { - float length; - float width; + float length=0; + float width=0; int correct = 0; float area; float aspectRatio; int goodRatio = 0; while (goodRatio == 0) { while (correct == 0) { + cout << "Please provide dimensions for your kite between 1 and 400 centimeters." << endl; cout << "How long is your kite in centimeters? "; cin >> length; cout << endl << "How wide is your kite in centimeters? "; cin >> width; - cout << endl << "Your kite is " << length << "cm long and " << width << "cm wide? 1=Yes/ 0=No "; + cout << endl << "Your kite is " << length << "cm long and " << width << " cm wide? 1=Yes/ 0=No "; cin >> correct; + if (width < 1 || width >400) { + cout << "Your width isn't a proper size, please reenter a width between 1 and 400 cm." << endl; + correct = 0; + }if (length < 1 || length >400) { + cout << "Your length isn't a proper size, please reenter a width between 1 and 400 cm." << endl; + correct = 0; + } cout << endl; } cout << "Calculating area in square meters..." << endl; - area = (length * width) / 2.0; - area = area / 10000; - cout << "Your Kite's area is " << area << "meters squared." << endl; + area = GetArea(length, width); + cout << "Your Kite's area is " << area << " meters squared." << endl; aspectRatio = (width / length); if (aspectRatio >= 1) { cout << "*Warning* You have a low aspect ratio of " << aspectRatio<< ". A lower aspect ratio would provide better stability for your kite, try haing a smaller width." << endl; @@ -43,10 +50,12 @@ int main() cout << "You have a good aspect ratio of " << aspectRatio << endl; } } - - - - +} +float GetArea(float length, float width) { + float area = 0; + area = (length * width) / 2.0; + area = area / 10000; + return area; } |