summaryrefslogtreecommitdiff
path: root/cs162/wk1/quickstop
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-06-01 12:15:18 -0700
committerFuwn <[email protected]>2022-06-01 12:15:18 -0700
commitdfe06c0de4d07ff0dc770e9a0819f94b1e660ae9 (patch)
treefa4554180923ea47b9618b3ad3d04f6183a12104 /cs162/wk1/quickstop
downloadcs162-main.tar.xz
cs162-main.zip
feat: initial commitHEADmain
Diffstat (limited to 'cs162/wk1/quickstop')
-rw-r--r--cs162/wk1/quickstop/CMakeLists.txt4
-rw-r--r--cs162/wk1/quickstop/quickstop.cc57
2 files changed, 61 insertions, 0 deletions
diff --git a/cs162/wk1/quickstop/CMakeLists.txt b/cs162/wk1/quickstop/CMakeLists.txt
new file mode 100644
index 0000000..59d03bd
--- /dev/null
+++ b/cs162/wk1/quickstop/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 3.21)
+project(wk1_quickstop)
+
+add_executable(wk1_quickstop quickstop.cc)
diff --git a/cs162/wk1/quickstop/quickstop.cc b/cs162/wk1/quickstop/quickstop.cc
new file mode 100644
index 0000000..208ac5c
--- /dev/null
+++ b/cs162/wk1/quickstop/quickstop.cc
@@ -0,0 +1,57 @@
+#include <iostream>
+
+// Print instructions
+void instructions();
+// Get and assign the input
+void getInput(double &, int &);
+// Calculate the adjusted price
+double price(double, int);
+// Output the adjusted price
+void giveOutput(double, int, double);
+
+int main() {
+ // Declare variables
+ double wholesalePrice;
+ int shelfDays;
+ double adjustedPrice;
+
+ instructions();
+ getInput(wholesalePrice, shelfDays);
+ adjustedPrice = price(wholesalePrice, shelfDays);
+ giveOutput(wholesalePrice, shelfDays, adjustedPrice);
+
+ return 0;
+}
+
+void instructions() {
+ // Output instructions
+ std::cout << "Enter the wholesale price and the number of days the item is"
+ "expected to be on shelf, get adjusted price.\n"
+ << std::endl;
+}
+
+void getInput(double &cost, int &turnover) {
+ // Get and assign input
+ std::cout << "Wholesale price: ";
+ std::cin >> cost;
+ std::cout << "Number of days item is expected to be on a shelf: ";
+ std::cin >> turnover;
+}
+
+double price(double cost, int turnover) {
+ // Compare `turnover` to get adjusted price
+ if (turnover <= 7) {
+ return cost + (5.0f / cost);
+ } else if (turnover > 7) {
+ return cost + (10.0f / cost);
+ }
+
+ return 0.0f;
+}
+
+void giveOutput(double cost, int turnover, double price) {
+ // Output adjusted price
+ std::cout << "\nIf an item costing $" << cost
+ << " is expected to be on a shelf for " << turnover
+ << " days, the item will cost $" << price << std::endl;
+}