开发者

Problem creating a simple menu function on fortran 95 using a module

I am just beginning to create a menu function on a module and I'm getting a fatal error, too many errors. I suspect this is probably due to one small mistake instead of multiple since the code is so simpl开发者_如何学Pythone as of right now.

Someone have any ideas?

Below is what I have so far. Obviously I have just begun, but already I am surprised why there is a problem. Thanks so much!

Also I'm a bit new to modules so I'm just curious can you tell if this is how to compile it? g95 themenu.f95 -o ba ??

Thanks.

 MODULE themenu
    IMPLICIT NONE

    INTEGER:: choices, opt
    opt=choices()

     CONTAINS

    INTEGER FUNCTION choices ()
    INTEGER:: opt

    DO
        PRINT*, "1: Add an item manually"
        PRINT*, "2: Add item(s) from a file"
        PRINT*, "3: Add random item from list of top ten list"
        PRINT*, "4: Print list with totals"
        PRINT*, "5: Sort list alphabetically"
        PRINT*, "6: Sort list by price"
        PRINT*, "7: Write list to file"
        PRINT*, "8: EXIT"
        PRINT*, " "
        PRINT*, "Please make your selection (enter a number): "
        READ*, opt
        IF (opt>=1 .AND. opt<=8)EXIT
        PRINT*, "INVALID CHOICE. MUST BE A NUMBER 1-8. PLEASE TRY AGAIN!"
    END DO
    choices=opt
    END FUNCTION
    END MODULE

Thanks! The Program that uses this module looks someting like this so far:

PROGRAM listman
USE themenu
IMPLICIT NONE
END PROGRAM


You can't have assignment statements in a module, only data type specifications and a CONTAINS section with procedures.

MODULE themenu
CONTAINS
    INTEGER FUNCTION choices ()
    IMPLICIT NONE
    INTEGER:: opt
    ....
    END FUNCTION
END MODULE

PROGRAM listman
USE themenu
IMPLICIT NONE
INTEGER :: opt
opt=choices()
END PROGRAM
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜