Fortran Coder

查看: 7750|回复: 6
打印 上一主题 下一主题

[读物] 彭国伦教材P98课后第三题

[复制链接]

25

帖子

8

主题

0

精华

熟手

F 币
143 元
贡献
81 点
跳转到指定楼层
楼主
发表于 2020-6-30 09:47:13 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
彭国伦教材P98课后第三题,所得税有三个等级,岁年龄不同有不同算法。求教我的程序错在哪里

无标1.jpg (338.71 KB, 下载次数: 363)

无标1.jpg
分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

954

帖子

0

主题

0

精华

大师

F 币
184 元
贡献
75 点

规矩勋章元老勋章新人勋章水王勋章热心勋章

QQ
沙发
发表于 2020-6-30 10:31:09 | 只看该作者
end case 改为 end select

25

帖子

8

主题

0

精华

熟手

F 币
143 元
贡献
81 点
板凳
 楼主| 发表于 2020-6-30 11:23:48 | 只看该作者
vvt 发表于 2020-6-30 10:31
end case 改为 end select

改了,还是有两个问题
错误        1         error #5082: Syntax error, found IDENTIFIER 'TAX' when expecting one of: THEN       
错误        2        Compilation Aborted (code 1)       

954

帖子

0

主题

0

精华

大师

F 币
184 元
贡献
75 点

规矩勋章元老勋章新人勋章水王勋章热心勋章

QQ
地板
发表于 2020-6-30 14:17:55 | 只看该作者
重新给你改正后的代码。尽可能复制粘贴(不截图)

25

帖子

8

主题

0

精华

熟手

F 币
143 元
贡献
81 点
5#
 楼主| 发表于 2020-6-30 16:32:35 | 只看该作者
好的
[Fortran] 纯文本查看 复制代码
program test0503
implicit none
integer age
real income,tax

write(*,*) "Input your age:"
read(*,*) age
write(*,*) "Input your income:"
read(*,*) income

select case(age)
case(0:49)
if(income>=0.0.and.income<=1000.0) then
  tax=income*0.03
else if(income>1000.0.and.income<=5000.0) then
  tax=income*0.10
else if(income>5000.0) then
  tax=income*0.15
else if(income<0.0)  tax=0
end if
case(50:)
if(income>=0.0.and.income<=1000.0) tax=income*0.05
if(income>1000.0.and.income<=5000.0) tax=income*0.07
if(income>5000.0) tax=income*0.10
if(income<0.0)  tax=0
case default
  tax=0
end select

write(*,*) "Tax:"
write(*,*) tax

stop
end

159

帖子

2

主题

1

精华

大师

Vim

F 币
961 元
贡献
469 点

规矩勋章

6#
发表于 2020-6-30 17:21:04 | 只看该作者
15235312522 发表于 2020-6-30 16:32
好的
program test0503
implicit none

[Fortran] 纯文本查看 复制代码
program test0503
implicit none
integer age
real income,tax

write(*,*) "Input your age:"
read(*,*) age
write(*,*) "Input your income:"
read(*,*) income

select case(age)
case(0:49)
if(income>=0.0.and.income<=1000.0) then
  tax=income*0.03
else if(income>1000.0.and.income<=5000.0) then
  tax=income*0.10
else if(income>5000.0) then
  tax=income*0.15
else if(income<0.0) then
!这个地方用了elseif就要用then
 tax=0
end if
case(50:)
if(income>=0.0.and.income<=1000.0) tax=income*0.05
if(income>1000.0.and.income<=5000.0) tax=income*0.07
if(income>5000.0) tax=income*0.10
if(income<0.0)  tax=0
case default
  tax=0
end select

write(*,*) "Tax:"
write(*,*) tax

stop
end

25

帖子

8

主题

0

精华

熟手

F 币
143 元
贡献
81 点
7#
 楼主| 发表于 2020-6-30 17:44:48 | 只看该作者
收到,程序正常了,谢谢老师
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

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

GMT+8, 2024-4-25 00:40

Powered by Tencent X3.4

© 2013-2024 Tencent

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