Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object NewestCalc extends App {
- var retry = false
- var total = 0.0
- var recalc = false
- var calc = true
- var mod = ""
- var one = 0.0
- var two = 0.0
- var calcstart = false
- var samenum = false
- def num():Double = {
- if (mod == "+") {
- return one + two
- }
- else if (mod == "-") {
- return one - two
- }
- else if (mod == "*") {
- return one * two
- }
- else if (mod == "/") {
- return one / two
- }
- else if (mod == "^") {
- return Math.pow(one,two)
- }
- else {
- println("invalid response.")
- return -0
- }
- }
- def numCheck():Unit = {
- if (total == -0) {
- calc = true
- recalc = false
- return retry = true
- }
- else {
- recalc = false
- calc = false
- return retry = false
- }
- }
- def samenumbcalc() = {
- var contcalc = readLine();
- if (contcalc.equalsIgnoreCase("Y")) {
- recalc = false
- calc = false
- samenum = true
- calcstart = true
- one = total
- }
- else {
- recalc = false
- println("continue calculating new numbers? Y/N")
- contcalc = readLine();
- if (contcalc.equalsIgnoreCase("Y")) {
- calcstart = true
- samenum = false
- }
- else {
- println("program terminated.")
- calcstart = false
- }
- }
- }
- def printans() = {
- if (retry == false) {
- println(""+total+"")
- println("continue calculating off "+total+"? Y/N.")
- samenumbcalc();
- }
- else {
- //Nothing printed
- }
- }
- def inputs() = {
- if (samenum == false) {
- do {
- println("input number one.")
- one = readDouble();
- println("input modifer.")
- mod = readLine();
- println("input number two.")
- two = readDouble();
- total = num();
- numCheck();
- printans();
- }
- while (calc == true)
- }
- else {
- do {
- println("input modifer.")
- mod = readLine();
- println("input number two.")
- two = readDouble();
- total = num();
- numCheck();
- printans();
- }
- while (recalc == true)
- }
- }
- do {
- inputs();
- }
- while (calcstart == true)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement