From 16af16310dbf9980c70b165f0660eec5f77436cf Mon Sep 17 00:00:00 2001 From: Timothy Glynn Date: Thu, 12 Dec 2019 15:35:35 -0500 Subject: [PATCH 1/2] softwriters --- CashRegister.csproj | 13 ++++ Program.cs | 152 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 42 +----------- input.txt | 3 + 4 files changed, 169 insertions(+), 41 deletions(-) create mode 100644 CashRegister.csproj create mode 100644 Program.cs create mode 100644 input.txt diff --git a/CashRegister.csproj b/CashRegister.csproj new file mode 100644 index 00000000..bd7ebde7 --- /dev/null +++ b/CashRegister.csproj @@ -0,0 +1,13 @@ + + + + Exe + netcoreapp2.2 + + + + + + + + diff --git a/Program.cs b/Program.cs new file mode 100644 index 00000000..af90ebd5 --- /dev/null +++ b/Program.cs @@ -0,0 +1,152 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; //so useful +using System.Text; + + + + +namespace CashRegister +{ + class Program + { + //private static StreamWriter writeToTextFile = new StreamWriter("output.txt"); + [STAThread] + public static void Main(string[] args) + { + + // read in file (all lines) + // store first line into an array + // create two arrays of decimals: one for rows, one for cols + // iterate through each line: store [0] into rows, [1] into cols + + // Read the file and display it line by line. + System.IO.StreamReader file = new System.IO.StreamReader(@"input.txt"); + + /* THIS IS THE KEY!!! store the entire array as the actual input of the file... duh */ + string[] lines = File.ReadAllLines("input.txt"); + + int i = 0; + + // iterate through "lines" - make sure it works by storing lines[0] as var and printing it + // split the first line into its own array. + // store 0,1 indexes of split array into vars (these are the vars we will use in calculations) + for(i=0; i= 1m) + { + dollars = Math.Truncate((change / 1m)); + change = change % 1m; + } + + while(change >= 0.25m) + { + quarters = Math.Truncate((change / 0.25m)); + change = change % 0.25m; + } + + while(change >= 0.10m) + { + dimes = Math.Truncate((change / 0.10m)); + change = change % 0.10m; + } + + while (change >= 0.05m) + { + nickels = Math.Truncate((change / 0.05m)); + change = change % 0.05m; + } + + while (change >= 0.01m) + { + pennies = Math.Truncate((change / 0.01m)); + change = change % 0.01m; + } + + + + string output = String.Format("{0} dollars, {1} quarters, {2} dimes, {3} nickels, {4} pennies", dollars, quarters, + dimes, nickels, pennies); + + Console.WriteLine(output); + + /* using (System.IO.StreamWriter fileout = new System.IO.StreamWriter(@"output.txt")) + { + System.IO.File.WriteAllText("output.txt", output); + }*/ + + + + + /* var coins = new [] { // ordered + new { name = "quarter", nominal = 0.25m }, + new { name = "dime", nominal = 0.10m }, + new { name = "nickel", nominal = 0.05m }, + new { name = "pennies", nominal = 0.01m } + }; + + foreach (var coin in coins) + { + Random rnd = new Random(); + int randNum = rnd.Next(1, 50); + //Console.WriteLine(randNum); + + int count = (int) (change / coin.nominal); + change -= count * coin.nominal; + + //Console.WriteLine("{0} {1},", count, coin.name); + + if(count == 0) { + // dont print the coin at all + } + else { + Console.WriteLine("{0} {1},", count, coin.name); + + } + + } + + Console.WriteLine(); // format properly*/ + } + + } + + } + +} + + + diff --git a/README.md b/README.md index 06a2101e..f0857338 100644 --- a/README.md +++ b/README.md @@ -1,41 +1 @@ -Cash Register -============ - -The Problem ------------ -Creative Cash Draw Solutions is a client who wants to provide something different for the cashiers who use their system. The function of the application is to tell the cashier how much change is owed and what denominations should be used. In most cases the app should return the minimum amount of physical change, but the client would like to add a twist. If the total due in cents is divisible by 3, the app should randomly generate the change denominations (but the math still needs to be right :)) - -Please write a program which accomplishes the clients goals. The program should: - -1. Accept a flat file as input - 1. Each line will contain the total due and the amount paid separated by a comma (for example: 2.13,3.00) - 2. Expect that there will be multiple lines -2. Output the change the cashier should return to the customer - 1. The return string should look like: 1 dollar,2 quarters,1 nickel, etc ... - 2. Each new line in the input file should be a new line in the output file - -Sample Input ------------- -2.12,3.00 - -1.97,2.00 - -3.33,5.00 - -Sample Output -------------- -3 quarters,1 dime,3 pennies - -3 pennies - -1 dollar,1 quarter,6 nickels,12 pennies - -*Remember the last one is random - -The Fine Print --------------- -Please use whatever techniques you feel are applicable to solve the problem. We suggest that you approach this exercise as if this code was part of a larger system. The end result should be representative of your abilities and style. We prefer that you submit your solution in a language targeting the .NET Framework to help us better evaluate your code. - -Please fork this repository. If your solution involves code auto generated by a development tool, please commit it separately from your own work. When you have completed your solution, please issue a pull request to notify us that you are ready. - -Have fun. +# CashRegister diff --git a/input.txt b/input.txt new file mode 100644 index 00000000..fba6116f --- /dev/null +++ b/input.txt @@ -0,0 +1,3 @@ +2.12,3.00 +1.97,2.00 +3.33,5.00 \ No newline at end of file From f884e134ad10f32bedb7d8be01033fdcce41e0c8 Mon Sep 17 00:00:00 2001 From: Timmy Glynn Date: Tue, 18 Feb 2020 17:58:24 -0500 Subject: [PATCH 2/2] good commit for cash register application --- .gitignore | 3 +++ .vscode/launch.json | 22 ++++++++++++++++++++++ .vscode/tasks.json | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..6bcf8b1e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin +obj +.DS_Store \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..8926d954 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch", + "type": "mono", + "request": "launch", + "program": "${workspaceRoot}/program.exe", + "cwd": "${workspaceRoot}" + }, + { + "name": "Attach", + "type": "mono", + "request": "attach", + "address": "localhost", + "port": 55555 + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 00000000..3a879640 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/CashRegister.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/CashRegister.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/CashRegister.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file