一道c语言的题目

cyply 2003-10-05 11:00:54
关于成绩评定的,居然搞不定,请大家帮帮忙。
#include<stdio.h>
#include<math.h>
main()
{
int score,temp;
char grade;
printf("please enter a score:");
scanf("%d",score);
if(score>100&&score<0)
printf("you have enter a wrong score,please enter the real again");
scanf("%d",score);
else //运行时提示这里失误,mispaced else in funtion main,
//请高手们指点指点是怎么回事。
if(score==100)
temp=9;
else
temp=(score-score%10)/10;
switch(temp)
{
case(9):grade='a';break;
case(8):grade='b';break;
case(7):grade='c';break;
case(6):grade='d';break;
case(5):
case(4):
case(3):
case(2):
case(1):
case(0):grade='f';
}
printf("the score is %d and the grade is %c",score,grade);
}
或有更好的算法请大家提示,多谢!
...全文
41 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
locky1982 2003-10-05
  • 打赏
  • 举报
回复
我来完了,要说的都说了
:(
cyply 2003-10-05
  • 打赏
  • 举报
回复
很感谢大家的帮忙,特别是uglykoala。
以后肯定多多来这里灌,也多多给大家送分:)
1root1 2003-10-05
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<math.h>
main()
{
int score,temp;
char grade;
printf("please enter a score:");
scanf("%d",score);
if(score>100&&score<0)
{
printf("you have enter a wrong score,please enter the real again");
scanf("%d",score);
}
else //运行时提示这里失误,mispaced else in funtion main,
//请高手们指点指点是怎么回事。
if(score==100)
temp=9;
else
temp=(score-score%10-1)/10;
switch(temp)
{
case(9):grade='a';break;
case(8):grade='b';break;
case(7):grade='c';break;
case(6):grade='d';break;
case(5):
case(4):
case(3):
case(2):
case(1):
case(0):grade='f';
}
printf("the score is %d and the grade is %c",score,grade);
}
uglykoala 2003-10-05
  • 打赏
  • 举报
回复
算法这样我觉得就可以了。还是比较不错的。
在就是if else 语句中的括号。如果语句中有两个以上的句子就要加括号了。
还有就是判断分数是不是在0——100以内的方法不要用if else
最好用do while
你写的这个代码,如果你连续输入两次大于100的分数就不能得到你想要的结果了。
#include<stdio.h>
#include<math.h>
main()
{
int score,temp;
char grade;
printf("please enter a score:");
scanf("%d",&score); 这里也有问题。应该是&score
if(score>100||score<0) // 这里也有问题。应该是||或者而不是&&
{printf("you have enter a wrong score,please enter the real again");
scanf("%d",&score);
}
else
if(score==100)
temp=9;
else
{ temp=(score-score%10)/10;
switch(temp)
{
case(9):grade='a';break;
case(8):grade='b';break;
case(7):grade='c';break;
case(6):grade='d';break;
case(5):
case(4):
case(3):
case(2):
case(1):
case(0):grade='f';
}
}
printf("the score is %d and the grade is %c",score,grade);
}
lemon520 2003-10-05
  • 打赏
  • 举报
回复
请仔细检查语法有没有错误!

#include<stdio.h>
#include<math.h>
void main()
{
int score,temp;
char grade;
printf("please enter a score:");
scanf("%d",&score);
if(score>100&&score<0)
{
printf("you have enter a wrong score,please enter the real again");
scanf("%d",score);
}
else //运行时提示这里失误,mispaced else in funtion main,
//请高手们指点指点是怎么回事。
{
if(score==100)
temp=9;
else
temp=(score-score%10)/10;
}
switch(temp)
{
case(9):grade='a';break;
case(8):grade='b';break;
case(7):grade='c';break;
case(6):grade='d';break;
case(5):
case(4):
case(3):
case(2):
case(1):
case(0):grade='f';
}
printf("the score is %d and the grade is %c",score,grade);
}

welcomefei 2003-10-05
  • 打赏
  • 举报
回复
同意akiko(弥弥)、ssbull(初学者) 的意见
少写了一组大括号
ssbull 2003-10-05
  • 打赏
  • 举报
回复
你少写了一组大括号,位置在:
if(score>100&&score<0) {
....
}
DESL 2003-10-05
  • 打赏
  • 举报
回复
我晕你犯了一个严重的错误scanf输入语句你看你少了什么&
akiko 2003-10-05
  • 打赏
  • 举报
回复
if(score>100&&score<0)
{//你丢了这个
printf("you have enter a wrong score,please enter the real again");
scanf("%d",score);
}//你丢了这个
else

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧