#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]'
高手帮我看看该怎么改呀!
sizeof()来测一个i(a[i])
没确定的数组,这是C语言的一忌来的
#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");
}
{
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整除!");
}
char
array[n]
=
{‘s’,。。}
用strlen的话输出时不确定数值,用sizeof对任何类型数组时最保险的
2.grade=scoresToGrade(roundScores);
数组名是不可以用作左值的,scoresToGrade返回的是char型,所以你可以直接定义一个char型变量就可以了,可以把char grade[2];
改为char grade;
3.看你的意思是想输出字符,所以在前面改动的基础上把printf("%s",grade);改为printf("%c",grade);就行了本回答被提问者采纳