From f034dbed3b231851051d5d2dc8c2fe44d458e4c3 Mon Sep 17 00:00:00 2001 From: DoolyBoi Date: Wed, 19 Oct 2022 20:04:11 -0700 Subject: made while loop to ask user input multiple times --- BlankConsoleLab/BlankConsoleLab.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp index 1c8c8f6..224af44 100644 --- a/BlankConsoleLab/BlankConsoleLab.cpp +++ b/BlankConsoleLab/BlankConsoleLab.cpp @@ -21,13 +21,27 @@ int main() { //seting up variables float length, width, area, aspectRatio; + bool dimensions = false; - //output prompt for user to enter length and width - cout << "Please enter the length and width of your kite (in that order)." << endl; - cin >> length >> width; + //keeps on looping until the user inputs a length and a width between 1 and 400 + while (!dimensions) + { + //output prompt for user to enter length and width + cout << "Please enter the length and width of your kite (in that order)." << endl; + cin >> length >> width; + + //output confirmation stating what the user input + cout << "So the length is " << length << "cm and the width is " << width << " cm." << endl; - //output confirmation stating what the user input - cout << "So the length is " << length << "cm and the width is " << width << " cm." << endl; + if (width > 400 || length > 400 || width < 1 || length < 1) + { + cout << "Please enter a width and length between 1 - 400. " << endl; + } + else { + dimensions = true; + break; + } + } //calculating area and turning it to square meteres area = ((width * length) / 2); @@ -46,5 +60,7 @@ int main() } + + } -- cgit v1.2.3