C语言问题 高手进!

#include<stdio.h>
#include"genlib.h"

double finalScores(int timeOfAbsence,double classRoomBehavior,double assignment,double examScores);
int round(double scores);
char scoresToGrade(double roundscores);

main(){

int timeOfAbsence,roundScores;
double classRoomBehavior,examScores,assignment,scores;
char grade[2];

printf("time of absence?");
scanf("%d",&timeOfAbsence);
printf("classroom behavior(0-10)?");
scanf("%lf",&classRoomBehavior);
printf("assignment(0-30)?");
scanf("%lf",&assignment);
printf("exam scores(0-100)?");
scanf("%lf",&examScores);
scores=finalScores(timeOfAbsence,classRoomBehavior,assignment,examScores);
roundScores=round(scores);
grade=scoresToGrade(roundScores);
printf("%s",grade);
}

/*
*Function:scores
*Usage:s=scores(timeOfAbsence,classRoomBehavior,assignment,examScores);
*---------------------------------------------------------------------------
*This function calulates the scores of each student.
*/
double finalScores(int timeOfAbsence,double classRoomBehavior,double assignment,double examScores)
{
double scores;

if(timeOfAbsence>=5){
return(0);
}else{
scores=classRoomBehavior+assignment+examScores*0.6;
return(scores);
}
}

/*
*Function:round
*Usage:f=round(x).
*------------------
*This function rounds off the numbers you give.
*/
int round(double x){
int X;

if(x>0){
X=x+0.5;
}else{
X=x-0.5;
}
return(X);
}

/*
*Function:scoresToGrade
*Usage:g=scoresToGrade(roundscores)
*-----------------------------
*This function transforms the scores to grade.
*/
char scoresToGrade(double roundscores)
{
int roundScores;

if(roundScores>=90){
return("A");
}
if((roundScores>=80)&&(roundScores<=89)){
return("B");
}
if((roundScores>=70)&&(roundScores<=79)){
return("C");
}
if((roundScores>=60)&&(roundScores<=69)){
return("D");
}else{
return("E");
}
}

C:\Users\hp\Desktop\Text1.c(24) : warning C4047: '=' : 'char [2]' differs in levels of indirection from 'char '
C:\Users\hp\Desktop\Text1.c(24) : error C2106: '=' : left operand must be l-value
C:\Users\hp\Desktop\Text1.c(56) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
C:\Users\hp\Desktop\Text1.c(58) : warning C4244: '=' : conversion from 'double ' to 'int ', possible loss of data
C:\Users\hp\Desktop\Text1.c(74) : warning C4047: 'return' : 'char ' differs in levels of indirection from 'char [2]'
C:\Users\hp\Desktop\Text1.c(77) : warning C4047: 'return' : 'char ' differs in levels of indirection from 'char [2]'
C:\Users\hp\Desktop\Text1.c(80) : warning C4047: 'return' : 'char ' differs in levels of indirection from 'char [2]'
C:\Users\hp\Desktop\Text1.c(83) : warning C4047: 'return' : 'char ' differs in levels of indirection from 'char [2]'
C:\Users\hp\Desktop\Text1.c(85) : warning C4047: 'return' : 'char ' differs in levels of indirection from 'char [2]'

高手帮我看看该怎么改呀!

1我觉得你定义a[i]这里有问题,定义数组是通常i是一个已知的数,所以定义后都有固定的长度,假如你定义一个数组a[100],如果这个这个数组是整形的你的长度就是2*100,如果是单精度的浮点数就是4*100,如此累推。上面的都是错误的,不能用
sizeof()来测一个i(a[i])
没确定的数组,这是C语言的一忌来的
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-12-24
此为正确答案:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int
main()
{
long
int
x,y,k;
int
i,b[3];
scanf("%ld
%ld",&x,&y);
k=(int)pow(x,y);/*注意pow函数返回值为double型,,要加强制转换*/
if(k<100)
printf("%ld^%ld=%ld
不足三位数\n",x,y,k);
else
{
for(i=0;i<3;i++)
{
b[i]=k%10;
k=k/10;
}
for(i=2;i>=0;i--)
printf("%d",b[i]);
}
system("pause");
}
第2个回答  2019-12-27
2.main()
{
int
year;
printf("请输入一个年份:\n");
scanf("%d",&year);
if((year%4==0&&year%100!=0)||(year%400==0))
printf("闰年!");
else
printf("不是闰年!");
}
3.
main()
{
int
num;
printf("请输入一个数:\n");
scanf("%d",&num);
if((num%3==0)||(num%5==0))
printf("能被3或5整除!");
else
printf("不能被3或5整除!");
}
第3个回答  2019-12-03
用sizeof关键字,strlen用于字符串数组求大小,而且如果你定义了
char
array[n]
=
{‘s’,。。}
用strlen的话输出时不确定数值,用sizeof对任何类型数组时最保险的
第4个回答  2009-10-23
1.首先return字符应该是单引号,不应该是双引号,否则表示的是字符串

2.grade=scoresToGrade(roundScores);
数组名是不可以用作左值的,scoresToGrade返回的是char型,所以你可以直接定义一个char型变量就可以了,可以把char grade[2];
改为char grade;

3.看你的意思是想输出字符,所以在前面改动的基础上把printf("%s",grade);改为printf("%c",grade);就行了本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网