Advertisement
Guest User

NewestCalc

a guest
Oct 4th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. object NewestCalc extends App {
  2. var retry = false
  3. var total = 0.0
  4. var recalc = false
  5. var calc = true
  6. var mod = ""
  7. var one = 0.0
  8. var two = 0.0
  9. var calcstart = false
  10. var samenum = false
  11. def num():Double =  {
  12.         if (mod == "+") {
  13.             return one + two
  14.         }
  15.         else if (mod == "-")    {
  16.             return one - two
  17.         }
  18.         else if (mod == "*")    {
  19.             return one * two
  20.         }
  21.         else if (mod == "/")    {
  22.             return one / two
  23.         }
  24.         else if (mod == "^")    {
  25.             return Math.pow(one,two)
  26.         }
  27.         else    {
  28.             println("invalid response.")
  29.             return -0
  30.         }
  31. }
  32. def numCheck():Unit =   {
  33.         if (total == -0)    {
  34.             calc = true
  35.             recalc = false
  36.             return retry = true
  37.         }
  38.         else    {
  39.             recalc = false
  40.             calc = false
  41.             return retry = false
  42.         }
  43. }
  44. def samenumbcalc() =    {
  45.     var contcalc = readLine();
  46.     if (contcalc.equalsIgnoreCase("Y")) {
  47.         recalc = false
  48.         calc = false
  49.         samenum = true
  50.         calcstart = true
  51.         one = total
  52.     }
  53.     else    {
  54.         recalc = false
  55.         println("continue calculating new numbers? Y/N")
  56.         contcalc = readLine();
  57.         if (contcalc.equalsIgnoreCase("Y")) {
  58.             calcstart = true
  59.             samenum = false
  60.         }
  61.         else    {
  62.             println("program terminated.")
  63.             calcstart = false
  64.         }
  65.     }
  66. }
  67. def printans() =    {
  68.     if  (retry == false)    {
  69.         println(""+total+"")
  70.         println("continue calculating off "+total+"? Y/N.")
  71.         samenumbcalc();
  72.     }
  73.     else    {
  74.         //Nothing printed
  75.     }
  76. }
  77. def inputs() =  {
  78.     if (samenum == false)   {
  79.         do  {
  80.             println("input number one.")   
  81.             one = readDouble();
  82.             println("input modifer.")
  83.             mod = readLine();
  84.             println("input number two.")
  85.             two = readDouble();
  86.             total = num();
  87.             numCheck();
  88.             printans();
  89.         }
  90.         while (calc == true)
  91.     }
  92.     else    {
  93.         do  {
  94.             println("input modifer.")
  95.             mod = readLine();
  96.             println("input number two.")
  97.             two = readDouble();
  98.             total = num();
  99.             numCheck();
  100.             printans();
  101.         }
  102.         while (recalc == true)
  103.     }
  104. }
  105. do  {
  106.     inputs();
  107. }
  108. while (calcstart == true)
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement