summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Williams <[email protected]>2022-10-15 11:16:52 -0700
committerJoseph Williams <[email protected]>2022-10-15 11:16:52 -0700
commitcc6a4dc3dcd87a6d857dd57d275592d51aac0608 (patch)
treeda1c1d0b36e4c566a35792692192d69429a90792
parentrevised aspect ratio calculations (diff)
downloadcst116-lab1-allthenamesaretaken3141-cc6a4dc3dcd87a6d857dd57d275592d51aac0608.tar.xz
cst116-lab1-allthenamesaretaken3141-cc6a4dc3dcd87a6d857dd57d275592d51aac0608.zip
Completed step 2-1 (limit user input, although I see no reason for the limits) and 2-2 (compute kite mass).
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index 898ab8b..892f002 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -8,6 +8,9 @@ using namespace std;
const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
+//I always put constants in all caps. Makes it easier to see what never gets changed.
+const float EARTH_GRAVITY = 9.807; //(m/s)
+
//Prints in full color with (optional) automatic line breaks. Requires <windows.h> Returns nothing and takes up to 4 parameters:
//console (HANDLE): Used for colored text. Always set it to hConsole and don't worry about it.
//text (string): The text to be printed. Don't put a newline at the end.
@@ -48,11 +51,11 @@ float getWidthOrHeight(string d)
while (true)
{
multiColorPrint(text);
- if (cin >> input) //This feels so wrong but it does in fact work.
+ if (cin >> input && 1 <= input <= 400) //This feels so wrong but it does in fact work.
{
break;
}
- colorPrint("Oh no! It looks like something went wrong.\nPlease make sure your width is a number and try again.", 12);
+ colorPrint("Oh no! It looks like something went wrong.\nPlease make sure your width is a number between 1 and 400 and try again.", 12);
cin.clear();
cin.ignore(80, '\n');
}
@@ -71,7 +74,7 @@ void aspectRatio(float width, float height)
float ratio = width / height;
multiColorPrint(vector<tuple<string, int, bool> > {make_tuple("Your kite has an aspect ratio of ", 15, false), make_tuple(to_string(ratio), 11, false), make_tuple(". ", 15, false)});
if (ratio >= 5) {
- colorPrint("That number should be above 1, yes, but this seems a little overkill.", 6);
+ colorPrint("Well, your aspect ratio is higher than 1, but this seems a little overkill.", 6);
}
else if (ratio >= 1) {
colorPrint("Your kite will fly nice and stable, provided you actually know how to fly it.", 10);
@@ -82,6 +85,12 @@ void aspectRatio(float width, float height)
}
}
+//Returns the mass of the kite in kilograms.
+float calculateKiteMass(float area)
+{
+ return area * 0.135;
+}
+
int main()
{
float width, height;
@@ -99,12 +108,15 @@ int main()
colorPrint("I'm sure it's beautiful.\n", 9);
//Calculate the kite's area and tell it to the user.
- float area = calulateKiteArea(width, height);
- multiColorPrint(vector<tuple<string, int, bool> > {make_tuple("Your kite has an area of ", 15, false), make_tuple(to_string(area) + " square meters", 11, false), make_tuple(". ", 15, true));
+ const float AREA = calulateKiteArea(width, height);
+ multiColorPrint(vector<tuple<string, int, bool> > {make_tuple("Your kite has an area of ", 15, false), make_tuple(to_string(AREA) + " square meters", 11, false), make_tuple(". ", 15, true)});
cout << endl;
//Do aspect ratio stuff.
aspectRatio(width, height);
+ const float MASS = calculateKiteMass(AREA);
+ multiColorPrint(vector<tuple<string, int, bool> >{make_tuple("Your kite has a mass of ", 15, false), make_tuple(to_string(MASS) + " kilograms", 11, false), make_tuple(".", 15, true)});
+
return 0;
} \ No newline at end of file