summaryrefslogtreecommitdiff
path: root/BlankConsoleLab
diff options
context:
space:
mode:
authorJoseph Williams <[email protected]>2022-10-13 15:35:37 -0700
committerJoseph Williams <[email protected]>2022-10-13 15:35:37 -0700
commite4a7fe53dbe331a1e543863a0523a30be2d68d66 (patch)
tree2c7893a4600f41ec7bd9a17c0ab0d6caef299e85 /BlankConsoleLab
parentSetting up GitHub Classroom Feedback (diff)
downloadcst116-lab1-allthenamesaretaken3141-e4a7fe53dbe331a1e543863a0523a30be2d68d66.tar.xz
cst116-lab1-allthenamesaretaken3141-e4a7fe53dbe331a1e543863a0523a30be2d68d66.zip
completed step 1 (ask user for width and height)
Diffstat (limited to 'BlankConsoleLab')
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp58
-rw-r--r--BlankConsoleLab/BlankConsoleLab.vcxproj8
2 files changed, 54 insertions, 12 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index ed5f807..8ca8157 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -1,16 +1,58 @@
-// BlankConsoleLab.cpp : This file contains the 'main' function. Program execution begins and ends there.
-//
-
#include <iostream>
+#include <windows.h> //colored couts go brrrr :)
using namespace std;
-using std::cout;
-using std::cin;
-using std::endl;
+const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
-int main()
+//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.
+//color (int): The color code of the text. Optional, defaults to white.
+//linebreak (bool): Whether to end the line after printing. Optional, defaults to true.
+void colorPrint(string text, int color = 15, bool linebreak = true, HANDLE console = hConsole)
+{
+ if (linebreak) //Add a line break to the end of the text unless told not to
+ {
+ text += "\n";
+ }
+ SetConsoleTextAttribute(console, color); //Use black magic (native OS commands) to change the color of any text we print.
+ cout << text;
+ SetConsoleTextAttribute(console, 15); //Use more black magic to set the color back to white so that we don't start randomly printing other colors.
+
+}
+
+//Super messy and really just here because if you're reusing more than one line, you're doing something wrong.
+int getWidthOrHeight(string d)
{
- cout << "Hello World!\n";
+ int input;
+ while (true)
+ {
+ cout << "Please enter the ";
+ colorPrint(d, 5, false);
+ cout << " of your kite in ";
+ colorPrint("cm", 5, false);
+ cout << ": ";
+ if (cin >> input) //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);
+ cin.clear();
+ cin.ignore(80, '\n');
+ }
+ return input;
}
+int main()
+{
+ int width, height;
+ bool haveWidth = false, haveHeight = false; //If the user has entered a valid width and height yet. Used for looping.
+
+ colorPrint("Welcome to Kite Calculator!\n", 9);
+
+ colorPrint("Let's start with getting the dimensions of your kite!", 11);
+ width = getWidthOrHeight("width");
+ height = getWidthOrHeight("height");
+
+} \ No newline at end of file
diff --git a/BlankConsoleLab/BlankConsoleLab.vcxproj b/BlankConsoleLab/BlankConsoleLab.vcxproj
index db2e734..d2e3ee2 100644
--- a/BlankConsoleLab/BlankConsoleLab.vcxproj
+++ b/BlankConsoleLab/BlankConsoleLab.vcxproj
@@ -29,26 +29,26 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
+ <PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>