Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin
obj
.DS_Store
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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
}
]
}
42 changes: 42 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
13 changes: 13 additions & 0 deletions CashRegister.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ChoETL" Version="1.1.0.4" />
<PackageReference Include="MongoDB.Driver" Version="2.9.3" />
</ItemGroup>

</Project>
152 changes: 152 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -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<lines.Length; i++)
{

string firstline = lines[i];

string[] splitLine = firstline.Split(',');
string payment = splitLine[0];
string price = splitLine[1];

decimal paymentVal = decimal.Parse(payment);
decimal priceVal = decimal.Parse(price);

//Console.WriteLine(paymentVal);
//Console.WriteLine(priceVal);

decimal change = priceVal - paymentVal;

//Console.WriteLine(total);

// lets create a cash register "drawer"
//int numDollars =0, numQuarters = 0, numDimes = 0, numNickels = 0, numPennies = 0;
Random rnd = new Random();
int numDollars = rnd.Next(0, 2);
int numQuarters = rnd.Next(0,41);
int numDimes = rnd.Next(0, 11);
int numNickels = rnd.Next(0,21);
int numPennies = rnd.Next(0,101);


decimal dollars = 0, quarters = 0, dimes = 0, nickels = 0, pennies = 0;

while(change >= 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*/
}

}

}

}



42 changes: 1 addition & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2.12,3.00
1.97,2.00
3.33,5.00