如何创建C程序 [英] How do I create a C program

查看:64
本文介绍了如何创建C程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建一个程序,询问用户他/她的最终成绩,并显示等效成绩(参见下表)及其评论。

等级

等价

备注





no。

letter



0.0

59.4

0.00

F

? ??

59.5

64.4

1.00

D

??? br />
64.5

70.4

1.50

D +

???

70.5

76.4

2.00

C

???

76.5

82.4

2.50

C +

???

82.5

88.4

3.00

B

???

88.5

94.4

3.50

B +

???

94.5

100.0

4

A

???



我尝试过:



#include< stdio.h>

main(){



/ *此程序将询问用户他们的最终成绩,它将显示等效成绩(参见下表)&它的评论

注意: - 你是那个创建自己的评论的人。这些评论应该激励他们

等级

从0.0到59.4是数字(0.0)其中F字母

从59.5到64.4是数字( 1.00)这是D / /
从64.5到70.4是数字(1.50)是D +

从70.5到76.4是数字(2.00)是C

从76.5到82.4是数字(2.50)是C +

从82.5到88.4是数字(3.00)这是B

从88.5到94.4是数字( 3.50)这是B +

从94.5到100.0是数字(4)这是A

样本输出

输入你的fina等级:55

当量等级是0.0或者F

评论=度过愉快的假期

* /

int grade, equi_grade_num,言论;

grade = 0到100.0

char a,b,c,d,f,p,l,u;

a ='A' ;

b ='B';

c ='C';

d ='D';

f =' F';

p ='B +';

l ='C +';

u ='D +';



printf(输入你的最终成绩:);

scanf(%d,& grade);



printf(您的等效等级为%d:或%c:);

scanf(%d%c,& equi_grade_num,& a,& ; b,& c,& d,& f,& p,& l,& u);



if(grade == 0 || grade< = 59.4){

scanf(%d%c,& equi_grade_num,& a,& b,& c,& d,& f ,& p,& l,& u);

printf(失败,需要立即改进);

}







getch();

}

Create a program that will ask the user for his/her final grade and it display the equivalent grade (refer to below table) and its remarks.
Grade
Equivalent
Remarks
from
to
no.
letter

0.0
59.4
0.00
F
???
59.5
64.4
1.00
D
???
64.5
70.4
1.50
D+
???
70.5
76.4
2.00
C
???
76.5
82.4
2.50
C+
???
82.5
88.4
3.00
B
???
88.5
94.4
3.50
B+
???
94.5
100.0
4
A
???

What I have tried:

#include<stdio.h>
main() {

/* This program will ask the user for their final grade and it will display the equivalent grade(refer to the below table) & its remarks
note:- you are the one to create your own remarks. the remarks should inspire them
Grades
from 0.0 to 59.4 is number (0.0) which F in letter
from 59.5 to 64.4 is number (1.00) which is D
from 64.5 to 70.4 is number (1.50) which is D+
from 70.5 to 76.4 is number (2.00) which is C
from 76.5 to 82.4 is number (2.50) which is C+
from 82.5 to 88.4 is number (3.00) which is B
from 88.5 to 94.4 is number (3.50) which is B+
from 94.5 to 100.0 is number (4) which is A
sample output
enter your fina grade : 55
equivalent grade is 0.0 or F
remark= "Have a nice vacation"
*/
int grade,equi_grade_num,remarks;
grade=0 to 100.0
char a, b, c, d, f, p, l, u;
a='A';
b='B';
c='C';
d='D';
f='F';
p='B+';
l='C+';
u='D+';

printf("Input your final grade: ");
scanf("%d",&grade);

printf("Your equivalent grade is %d: or %c: ");
scanf("%d" "%c",&equi_grade_num,&a,&b,&c,&d,&f,&p,&l,&u);

if (grade==0 || grade<=59.4) {
scanf("%d" "%c",&equi_grade_num,&a,&b,&c,&d,&f,&p,&l,&u);
printf("Failed,needs immediate improve");
}



getch();
}

推荐答案

这不会起作用 - 你可能已经注意到了!

一个 char 变量只能持有一个字母,所以这样的事情:

That isn't going to work - as you have probably noticed!
A char variable can only hold a single "letter", so things like this:
p='B+';
l='C+';
u='D+';

无法编译。

回到舞台上,再想一想:分阶段这样做。

首先从用户那里获得一个成绩,并将其存储在适当的变量中 - 而 int 变量只保存整数值,因此它们不适用于59.4,或者88.5。你必须为你的成绩使用不同的数据类型。



当你有工作时(我的意思是编译它,运行它并确保当用户输入一个值,您可以将其作为数字读取并正确打印出来,拒绝任何坏输入,如你好)看看哪个组等级落入。这并不复杂,它只是一组如果......其他如果......其他如果......其他陈述:

Will not compile.
Go back a stage, and think again: do this in stages.
Start by getting a grade from the user, and storing it in an appropriate variable - and int variables only hold integer values, so they don't work with "59.4", or "88.5". You will have to use a different data type for your grade.

When you have that working (and by that I mean compile it, run it and make sure that when the user enters a value you can read it as a number and print it back out correctly, rejecting any "bad" inputs like "hello") look at working out which "group" the grade falls into. That's not complex, it's just a set of if...else if...else if...else statements:

if (grade >= lowestGradeInFirstGroup && grade <= highestGradeInFirstGroup)
   {
   ... In first group
   }
else if (grade >= lowestGradeInSecondGroup && grade <= highestGradeInSecondGroup)
   {
   ... in second group
   }
...
else
   {
   ... in last group
   }

当你有工作(编译并运行正常)时,请查看相应的成绩代码和消息。



分阶段进行,并且它会很简单!

但是......这是你的作业,所以代码完全取决于你!

When you have that working (compiling and running ok) look at printing the appropriate grade code and message.

Do it in stages, and it'll be pretty easy!
But ... this is your homework, so the code is all up to you!


这篇关于如何创建C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆