- #1
mattmac.nuke
- 22
- 0
Alright, so I've updated it once more... The only thing I need to do is figure out how to convert the functions x_data, y_data and choi_1 that store all 3 of the inputs I need for the main program and other functions.
program calculator
IMPLICIT NONE
REAL :: addition, subtraction, multiplication, division, x, y, j, k, x_data, y_data !x = A, y = B
CHARACTER :: choice, a, b, c, d, l, choi_1WRITE (*,*) ' '
WRITE (*,*) 'LAB 6- Baby Calculator'
WRITE (*,*) '----------------------'j = x_data(x)
k = y_data(y)
l = choi_1(choice)
SELECT CASE (l)
CASE ('A','a')
WRITE (*,*) 'A+B = ', addition (x, y)
CASE ('B','b')
WRITE (*,*) 'A-B = ', subtraction (x, y)
CASE ('C','c')
WRITE (*,*) 'A*B = ', multiplication (x, y)
CASE ('D','d')
WRITE (*,*) 'A/B = ', division(x, y)
END SELECT
end program calculator
CHARACTER FUNCTION choi_1 (choice)
IMPLICIT NONE
CHARACTER :: choice
WRITE (*,*) ' A) A+B'
WRITE (*,*) ' B) A-B'
WRITE (*,*) ' C) A*B'
WRITE (*,*) ' D) A/B'
WRITE (*,*) 'Enter choice:'
READ (*,*) choice
choi_1 = choice
END FUNCTION choi_1
REAL FUNCTION x_data (x)
IMPLICIT NONE
REAL :: x
WRITE (*,*) 'Enter a value A:'
READ (*,*) x
x_data = x
END FUNCTION x_data
REAL FUNCTION y_data (y)
IMPLICIT NONE
REAL :: y
WRITE (*,*) 'Enter a value B:'
READ (*,*) y
y_data = y
END FUNCTION y_dataREAL FUNCTION addition (x, y)
IMPLICIT NONE
REAL, INTENT(IN) :: x, y
addition = x + y
END FUNCTION addition
REAL FUNCTION subtraction (x, y)
IMPLICIT NONE
REAL, INTENT(IN) :: x, y
subtraction = x - y
END FUNCTION subtraction
REAL FUNCTION multiplication (x, y)
IMPLICIT NONE
REAL, INTENT(IN) :: x, y
multiplication = x*y
END FUNCTION multiplication
REAL FUNCTION division (x, y)
IMPLICIT NONE
REAL, INTENT(IN) :: x, y
IF ( y == 0) THEN
division = 0
ELSE
division = x/y
END IF
END FUNCTION division
program calculator
IMPLICIT NONE
REAL :: addition, subtraction, multiplication, division, x, y, j, k, x_data, y_data !x = A, y = B
CHARACTER :: choice, a, b, c, d, l, choi_1WRITE (*,*) ' '
WRITE (*,*) 'LAB 6- Baby Calculator'
WRITE (*,*) '----------------------'j = x_data(x)
k = y_data(y)
l = choi_1(choice)
SELECT CASE (l)
CASE ('A','a')
WRITE (*,*) 'A+B = ', addition (x, y)
CASE ('B','b')
WRITE (*,*) 'A-B = ', subtraction (x, y)
CASE ('C','c')
WRITE (*,*) 'A*B = ', multiplication (x, y)
CASE ('D','d')
WRITE (*,*) 'A/B = ', division(x, y)
END SELECT
end program calculator
CHARACTER FUNCTION choi_1 (choice)
IMPLICIT NONE
CHARACTER :: choice
WRITE (*,*) ' A) A+B'
WRITE (*,*) ' B) A-B'
WRITE (*,*) ' C) A*B'
WRITE (*,*) ' D) A/B'
WRITE (*,*) 'Enter choice:'
READ (*,*) choice
choi_1 = choice
END FUNCTION choi_1
REAL FUNCTION x_data (x)
IMPLICIT NONE
REAL :: x
WRITE (*,*) 'Enter a value A:'
READ (*,*) x
x_data = x
END FUNCTION x_data
REAL FUNCTION y_data (y)
IMPLICIT NONE
REAL :: y
WRITE (*,*) 'Enter a value B:'
READ (*,*) y
y_data = y
END FUNCTION y_dataREAL FUNCTION addition (x, y)
IMPLICIT NONE
REAL, INTENT(IN) :: x, y
addition = x + y
END FUNCTION addition
REAL FUNCTION subtraction (x, y)
IMPLICIT NONE
REAL, INTENT(IN) :: x, y
subtraction = x - y
END FUNCTION subtraction
REAL FUNCTION multiplication (x, y)
IMPLICIT NONE
REAL, INTENT(IN) :: x, y
multiplication = x*y
END FUNCTION multiplication
REAL FUNCTION division (x, y)
IMPLICIT NONE
REAL, INTENT(IN) :: x, y
IF ( y == 0) THEN
division = 0
ELSE
division = x/y
END IF
END FUNCTION division
Attachments
Last edited: