程序未完全打印
Program is not printing completely
我第一次尝试编程,但没有得到这个 program.Though 的输出它看起来很简单,但是在输入姓名、名次、学生获得的分数等输入后代码不会打印。
我附上了编译器的截图。
谢谢!
#include<stdio.h>
int main()
{
int roll,phy,che,ca,total;
float percentage;
char name[20];
printf("enter the name of student: "); //studentname
scanf("%s",&name);
printf("enter the roll number: "); //roll number
scanf("%d",&roll);
printf("enter the marks obtained in phy,che,ca: "); //marks obtained/subject
scanf("%d%d%d ",&phy,&che,&ca);
//doesnt works from here.
total= (phy+che+ca); //calculating total marks
printf("the total marks obtained is %d\n",total);
percentage =total/3.0; //calculating percentage student got.
printf("the total percentage obtained is %d\n",percentage);
if(percentage>=80)
printf("first division\n"); //first division
else if(percentage>=60 && percentage<=80)
printf("second division\n"); //second division
else if(percentage>=60)
printf("third divison\n"); //third division
else if(percentage>=10)
printf("you failed!\n"); //failed
else
printf("invalid input\n"); //invalid input
return 0;
}
screenshot of the compiler
scanf("%d%d%d ",&phy,&che,&ca);
格式多了一个空白字符。所以你输入3个整数后应该再输入一个字符。
而且你不应该使用 %d
来打印浮点型变量,你应该使用 %f
.
我第一次尝试编程,但没有得到这个 program.Though 的输出它看起来很简单,但是在输入姓名、名次、学生获得的分数等输入后代码不会打印。 我附上了编译器的截图。 谢谢!
#include<stdio.h>
int main()
{
int roll,phy,che,ca,total;
float percentage;
char name[20];
printf("enter the name of student: "); //studentname
scanf("%s",&name);
printf("enter the roll number: "); //roll number
scanf("%d",&roll);
printf("enter the marks obtained in phy,che,ca: "); //marks obtained/subject
scanf("%d%d%d ",&phy,&che,&ca);
//doesnt works from here.
total= (phy+che+ca); //calculating total marks
printf("the total marks obtained is %d\n",total);
percentage =total/3.0; //calculating percentage student got.
printf("the total percentage obtained is %d\n",percentage);
if(percentage>=80)
printf("first division\n"); //first division
else if(percentage>=60 && percentage<=80)
printf("second division\n"); //second division
else if(percentage>=60)
printf("third divison\n"); //third division
else if(percentage>=10)
printf("you failed!\n"); //failed
else
printf("invalid input\n"); //invalid input
return 0;
}
screenshot of the compiler
scanf("%d%d%d ",&phy,&che,&ca);
格式多了一个空白字符。所以你输入3个整数后应该再输入一个字符。
而且你不应该使用 %d
来打印浮点型变量,你应该使用 %f
.