module CalculatorModule
 public :: Calculator
contains
 subroutine Calculator()
   character(len=1) :: command
   real :: input_number
   real :: current_total
    current_total = 0.0
    print *, "Enter a command ..."
    print *, ""
    print *, " A: Add      a number to the total"
    print *, " S: Subtract a number from the total"
    print *, " M: Multiply a number by the total"
    print *, " D: Divide   a number from the total"
    print *, ""
    print *, " C: Clear the total to zero"
    print *, ""
    print *, " Q: Quit"
    do
       read *, command
       select case (command)
       case ("A", "a")
          print *, "Enter number to add: "
          read *, input_number
          current_total = current_total + input_number
       case ("S", "s")
          print *, "Enter number to subtract: "
          read *, input_number
          current_total = current_total - input_number
       case ("M", "m")
          print *, "Enter number to multiply: "
          read *, input_number
          current_total = current_total * input_number
       case ("D", "d")
          print *, "Enter number to divide: "
          read *, input_number
          current_total = current_total / input_number
       case ("C", "c")
          current_total = 0.0
       case ("Q", "q")
          exit
       case default
          print *, "Command must be A, S, M, D, C or Q"
       endselect
       print *, "The current total is: ", current_total
       print *, ""
       print *, "(A)dd, (S)ubtract, (M)ultiply, (D)ivide"
       print *, " (C)lear or (Q)uit"
    enddo
    print *, "Goodbye for now."
 endsubroutine Calculator
endmodule CalculatorModule
