c# - Issue with method to calculate and display -


so, i'm having issue programming assignment (i'm not going lie, homework). teacher assigned following: input user total of purchase , amount submitted, call single method main routine calculates , displays results (where results change user gets in hundred dollar bills, fifty dollar bills, etc. have workable code problem, know i'm not fulfilling requirements. have "gut feeling" there's better way write code isn't bulky. i'm looking suggestions on how improve code have. in advance help.

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks;  namespace change {     class change     {         static void main(string[] args)         {             //initialize variables             double costofpurchase = 0;             double amountsubmitted = 0;             double hundreddollarbills = 0;             double fiftydollarbills = 0;             double twentydollarbills = 0;             double fivedollarbills = 0;             double quarters = 0;             double nickles = 0;             double pennies = 0;              //set try catch errors user input             try             {                 //get cost of sale                 console.write("enter total cost of purchase: ");                 costofpurchase = convert.todouble(console.readline());                  if (costofpurchase < 0)                 {                     console.writeline("the cost of purchase cannot negative value.");                 }                  //get amount submitted pay sale                 console.write("enter amount submitted: ");                 amountsubmitted = convert.todouble(console.readline());                 if (costofpurchase > amountsubmitted)                 {                     console.writeline("you have not submitted enough money.");                 }                  //call method calculate , display change due                 calculatechangedue(costofpurchase, amountsubmitted, out hundreddollarbills, out fiftydollarbills, out twentydollarbills, out fivedollarbills, out quarters, out nickles, out pennies);                  console.writeline(hundreddollarbills + " hundred(s)");                 console.writeline(fiftydollarbills + " fifty");                 console.writeline(twentydollarbills + " twenty(s)");                 console.writeline(fivedollarbills + " five");                 console.writeline(quarters + " quarter(s)");                 console.writeline(nickles + " nickle");                 console.writeline(pennies + " penny(s)");                  //keep console open in debug mode                 console.write("press key exit.");                 console.readkey();             }             catch (system.exception e)             {                 console.writeline("an error has occurred.");                 console.writeline("the eror was: {0}", e.message);                 console.readline();             }         }          //method calculate , display change due         private static void calculatechangedue(double costofpurchase, double amountsubmitted, out double hundreddollarbills, out double fiftydollarbills, out double twentydollarbills, out double fivedollarbills, out double quarters, out double nickles, out double pennies)         {             //initialize variables             double changedue = 0;             double remainingchange = 0;              //calculate change due             changedue = amountsubmitted - costofpurchase;              remainingchange = changedue % 100;             hundreddollarbills = (changedue / 100) - (remainingchange / 100);              fiftydollarbills = (remainingchange / 50) - ((remainingchange % 50) / 50);             remainingchange = remainingchange % 50;              twentydollarbills = (remainingchange / 20) - ((remainingchange % 20) / 20);             remainingchange = remainingchange % 20;              fivedollarbills = (remainingchange / 5) - ((remainingchange % 5) / 5);             remainingchange = remainingchange % 5;              quarters = (remainingchange / 0.25) - ((remainingchange % 0.25) / 0.25);             remainingchange = remainingchange % 0.25;              nickles = (remainingchange / 0.05) - ((remainingchange % 0.05) / 0.05);             remainingchange = remainingchange % 0.05;              pennies = (remainingchange / 0.01) - ((remainingchange % 0.01) / 0.01);         }     } } 


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -