Fortran Coder

查看: 11790|回复: 5
打印 上一主题 下一主题

[求助] 书上一个猜数字游戏代码总是报错,求大神帮忙看下。。

[复制链接]

5

帖子

1

主题

0

精华

入门

萌新

F 币
35 元
贡献
16 点
跳转到指定楼层
楼主
发表于 2017-8-18 15:09:02 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
报错提示:
IVF2011
[Fortran] 纯文本查看 复制代码
!select case 语句范例
    program test001
    implicit none
    !变量申明
    real::result
    real::plus,minus
    integer::guess
    integer::i
    !可执行段
    print*,'what is the number?'
    print*,'play the game?[0-exit 1-play]'
    read(*,*)i
    !初始化
    do while(0/=i)
        call random_number(result)
        call random_number(plus)
        call random_number(minus)
        result=100.0*result+1.0
        plus=10.0*plus
        minus=20.0*minus
        write(*,'(1x,a,i3,",",i3,a)')'the number is in the range of[', && int(result)-int(minus),int(result)+int(plus)),']'
        print*,'your guess is?'
        !循环猜测
        do i=1,5
            read(*,*)guess
            select case(int(result))==guess)
            case(.true.)
                print*,'congratulation! you get the number!'
                write(*,'(1x,"and your score is:",i3)') 6-i
                exit
            case default
                write(*,*)'so sad,you almost get the number'
                if(5==i) then
                    print*,'sorry,you have lost your five times!'
                    write(*,'(1x,a,i3)'),"and the right number is:',int(result)
                else
                    print*,'your new guess is?'
                endif
            end select
        enddo
        print*,'continue the game?[0-exit 1-continue]'
        read(*,*)i
    enddo
    print*,'thanks for playing'
    end program test001

001.jpg (42.01 KB, 下载次数: 341)

生成解决方案时

生成解决方案时
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

5

帖子

1

主题

0

精华

入门

萌新

F 币
35 元
贡献
16 点
沙发
 楼主| 发表于 2017-8-18 15:14:06 | 只看该作者
write(*,'(1x,a,i3,",",i3,a)')' 这语句是什么意思,,,,,真心不懂

235

帖子

0

主题

0

精华

版主

World Analyser

F 币
630 元
贡献
464 点

新人勋章美女勋章元老勋章热心勋章规矩勋章管理勋章

QQ
板凳
发表于 2017-8-18 18:48:48 | 只看该作者
都是一些基本的书写错误。见注释
[Fortran] 纯文本查看 复制代码
!select case 语句范例
    program test001
    implicit none
    !变量申明
    real::result
    real::plus,minus
    integer::guess
    integer::i
    !可执行段
    print*,'what is the number?'
    print*,'play the game?[0-exit 1-play]'
    read(*,*)i
    !初始化
    do while(0/=i)
        call random_number(result)
        call random_number(plus)
        call random_number(minus)
        result=100.0*result+1.0
        plus=10.0*plus
        minus=20.0*minus
        write(*,'(1x,a,i3,",",i3,a)')'the number is in the range of[', &
         int(result)-int(minus),int(result)+int(plus),']'!多一个括号
        print*,'your guess is?'
        !循环猜测
        do i=1,5
            read(*,*)guess
            select case(int(result)==guess)!多一个括号
            case(.true.)
                print*,'congratulation! you get the number!'
                write(*,'(1x,"and your score is:",i3)') 6-i
                exit
            case default
                write(*,*)'so sad,you almost get the number'
                if(5==i) then
                    print*,'sorry,you have lost your five times!'
                    write(*,'(1x,a,i3)'),"and the right number is:",int(result)!双引号
                else
                    print*,'your new guess is?'
                endif
            end select
        enddo
        print*,'continue the game?[0-exit 1-continue]'
        read(*,*)i
    enddo
    print*,'thanks for playing'
    end program test001

235

帖子

0

主题

0

精华

版主

World Analyser

F 币
630 元
贡献
464 点

新人勋章美女勋章元老勋章热心勋章规矩勋章管理勋章

QQ
地板
发表于 2017-8-18 18:50:03 | 只看该作者
write(*,'(1x,a,i3,",",i3,a)')' 这语句是什么意思,,,,,真心不懂
这句意思是输出,用括号中的格式,即:
(1x,a,i3,",",i3,a)
其中
1x 表示先输出一个空格
a 表示输出一个字符串
i3 表示输出一个整数,占3格
"," 表示输出一个逗号

5

帖子

1

主题

0

精华

入门

萌新

F 币
35 元
贡献
16 点
5#
 楼主| 发表于 2017-8-21 10:17:28 | 只看该作者
kyra 发表于 2017-8-18 18:50
write(*,'(1x,a,i3,",",i3,a)')' 这语句是什么意思,,,,,真心不懂
这句意思是输出,用括号中的格式,即 ...

谢谢 已经可以运行了

5

帖子

1

主题

0

精华

入门

萌新

F 币
35 元
贡献
16 点
6#
 楼主| 发表于 2017-8-21 10:20:52 | 只看该作者
kyra 发表于 2017-8-18 18:48
都是一些基本的书写错误。见注释
[mw_shl_code=fortran,true]!select case 语句范例
    program test001

费心啦
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-4-25 12:18

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表