Skip to content

Instantly share code, notes, and snippets.

@camkidman
Created November 10, 2013 21:49
Show Gist options
  • Save camkidman/7404418 to your computer and use it in GitHub Desktop.
Save camkidman/7404418 to your computer and use it in GitHub Desktop.
// File Prolog
// Name: Cameron J Kidman
// CS 1400 Section 002
// Project: CS1400_Lab_20
// Date: 11/8/2013 0947
//
// I declare that the following code was written by me or provided
// by the instructor for this project. I understand that copying source
// code from any other source constitutes cheating, and that I will receive
// a zero on this project if I am found in violation of this policy.
// ---------------------------------------------------------------------------
using System;
static class Program
{
// some class level constants
const int HALVES = 50;
const int QUARTERS = 25;
const int DIMES = 10;
const int NICKELS = 5;
const int PENNIES = 1;
static void Main()
{
int money = 0; // the value we want to count change for
int numberCoins = 0;
do
{
Console.Clear();
Console.WriteLine("I will make change for you.");
Console.Write("Enter in an amount between 1 and 99: ");
if( int.TryParse(Console.ReadLine( ) , out money)==false)
{
Console.WriteLine("Invalid int value for money!");
Console.ReadLine();
continue;
}
Console.WriteLine("For your money {0} you get:", money);
ComputeChange(ref money, HALVES, out numberCoins);
Console.WriteLine("{0} halves", numberCoins );
ComputeChange(ref money, QUARTERS, out numberCoins);
Console.WriteLine("{0} quarters", ComputeChange(ref money, QUARTERS) );
ComputeChange(ref money, DIMES, out numberCoins);
Console.WriteLine("{0} dimes", ComputeChange(ref money, DIMES) );
ComputeChange(ref money, NICKELS, out numberCoins);
Console.WriteLine("{0} nickels", ComputeChange(ref money, NICKELS) );
ComputeChange(ref money, PENNIES, out numberCoins);
Console.WriteLine("{0} pennies\n", ComputeChange(ref money, PENNIES) );
Console.ReadLine( );
}while(true);
}
// The ComputeChange Method
// Add your method prolog here
static void ComputeChange(ref int changeValue, int coinValue, out int nCoins )
{
// you provide the method to compute change here
// divide changeValue by coinValue and return the number of coins
// nCoins += (changeValue / coinValue);
nCoins = (changeValue / coinValue);
changeValue -= (nCoins * coinValue);
changeValue.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment