In: Computer Science
Complete the 3 programming problems in this assignment by using
Microsoft Visual Studio Suite. Compile your solutions for each
problem solved in a Word or Google document which includes (a) the
pseudocode, (b) the C# codes and (c) the execution result (screen
capture just the answer part using Snipping Tool, avoiding
non-related or blank spaces). Notice for readability, that the (a)
& (b) are in text mode and the (c) is in image mode. Use proper
titles and wording in the results, such as Console.WriteLine("The
total change to be made is {0:C}.", change); so that the results
could be easily understood by a third party reader. For all 3
questions, assign the provided initial values to the variables or
constants in the source code as input.
You may need to save the snipped image as a JPG file and then
insert the file into the document, especially when you use a Google
doc. Create just one document for all 3 solutions in this
assignment. You may create the document directly from a cloud
service or from you PC first and then upload it to a cloud. The
possible cloud service could be Google Drive, Microsoft OneDrive,
Dropbox, etc. To submit the document, click the "Write Submission"
button under this assignment. Then use the opened editor box to
submit the web address of your document on the cloud or, if you are
not yet able to use a cloud service, submit the document as an
attached file.
Q2. Write a C# program that the number of twenty, ten, five,
dollar, quarter, dime, nickel, and penny that a customer should get
back as change. The goal is to use the least numbers of bills and
coins. Run your program once by initializing the change as $77.92.
Then change the source code to initialize the change as $23.27.
Record both C# codes and results as images in the submission
document. (Hint: It's easier to convert $77.92 to 7792 pennies and
use the penny as the basic unit to for all conversions.
Alternatively, you may use the dollar for the whole dollar part and
the penny for less than one dollar part as the basic units.)
using System;
public class changeMaker
{
///
public static void Main(string[] args)
{
Scanner keyboard = new
Scanner(System.in);
int price;
int provided;
int change;
Console.Write("Enter the purchase
price:");
price = (int)
Math.Round(keyboard.NextDouble() * 100);
Console.Write("Enter the amount
given by the customer:");
provided = (int)
Math.Round(keyboard.NextDouble() * 100);
if (provided > price)
{
Console.WriteLine("The customer should be given the change as
follows:");
change =
provided - price;
// Since you
multiplied by 100 you have to divide by 2000 to get the number of
twenties for change.
int twenties
= change / 2000;
if (twenties
> 0)
{ //if the
change is less than $20 this will be a zero
change = change % 2000; // this resets the value
of change to the remainder after the twenties are calculated but
only if there was at least enough to make one twenty
Console.WriteLine(twenties + " $20
bill(s)");
}
int tens =
change / 1000;
if (tens >
0)
{
change = change % 1000;
Console.WriteLine(tens + " $10 bill(s)");
}
int fives =
change / 500;
if (fives >
0)
{
change = change % 500;
Console.WriteLine(fives + " $5 bill(S)");
}
int ones =
change / 100;
if (ones >
0)
{
change = change % 100;
Console.WriteLine(ones + " $1 bill(s)");
}
int quarters =
change / 25;
if (quarters
> 0)
{
change = change % 25;
Console.WriteLine(quarters + " quarter
coin(s)");
}
int dimes =
change / 10;
if (dimes >
0)
{
change = change % 10;
Console.WriteLine(dimes + " dime
coin(s)");
}
int nickels =
change / 5;
if (nickels >
0)
{
change = change % 5;
Console.WriteLine(nickels + " nickel
coin(s)");
}
int pennies =
change;
Console.WriteLine(pennies + " penny coin(s)");
}
if (provided < price)
{ // this statement is saying that
if the customer doesn't pay enough, it will tell the user
Console.Write("Not enough money!");
}
else if (provided == price)
{ // this statement says if the
amount provided matches the price, then there is no change
necessary
Console.Write("No change is necessary!");
}
}
}