你好!世界C程序问题 [英] hello!world C program problem
本文介绍了你好!世界C程序问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好frndz,每当我执行我的代码时,我的代码中就有问题,它没有显示所获得的标记结果,这是什么问题..这是代码
hello frndz , i got a problem in my code whenever i excute my code it dont show the obtained marks result whats the problem in it .. here is the code
#include<stdio.h>
#include<conio.h>
void main ()
{
float physics,obt,a,b,d,e,f,g,c,maths,computer,english,urdu,pakstudies;
float total,avg,percentage;
clrscr();
printf(" \n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
printf(" \nkindly enter your total marks and obtained marks of each subject");
printf(" \n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
printf(" \nEnter total marks of physics:");
scanf("%f",&physics);
printf(" \nEnter obtained marks in physics:");
scanf("\n\t %f",&a);
c=(a/physics)*100;
printf("%.3f",c);
if(c<40)
{printf("\n u R fail in physics:(");
getch();
clrscr();
}
else if(c>=40)
{
printf("\n u R pass in physics:)");
getch();
clrscr();
}
printf(" \nEnter total marks of maths:");
scanf("%f",&maths);
printf(" \nEnter obtained marks of maths:");
scanf("%f",&b);
c=(b/maths)*100;
printf("\n\t %.3f",c);
if(c<40)
{
printf("\nu R fail in maths:(");
getch();
clrscr();
}
else if(c>=40)
{
printf("\n u R pass in maths:)");
getch();
clrscr();
}
printf(" \nEnter total marks of computer:");
scanf("%f",&computer);
printf(" \nEnter obtained marks of computer:");
scanf("\n\t %f",&d);
c=(d/computer)*100;
printf("\n\t %.3f",c);
if(c<40)
{
printf("\n u R fail in computer:( ");
getch();
clrscr();
}
else if(c>=40)
{
printf("\n u R pass in computer:)");
getch();
clrscr();
}
printf(" \nEnter total marks of english:");
scanf("%f",&english);
printf(" \nEnter obtained marks of english:");
scanf("%f",&e);
c=(e/english)*100;
printf("\n\t %.3f",c);
if(c<40)
{
printf("\nu R fail in english:( ");
getch();
clrscr();
}
else if(c>=40)
{
printf("\n u R pass in english:) ");
getch();
clrscr();
}
printf(" \nEnter the marks of urdu:");
scanf("%f",&urdu);
printf(" \nEnter obtained marks of urdu:");
scanf("%f",&f);
c=(f/urdu)*100;
printf("\n\t %.3f",c);
if(c<40)
{
printf("\n u R fail in urdu:( ");
getch();
clrscr();
}
else if(c>=40)
{
printf("u R pass in urdu:) ");
getch();
clrscr();
}
printf(" \nenter the marks of pakstudies:");
scanf("%f",&pakstudies);
printf(" \nEnter obtained marks of pakstudies:");
scanf("%f",&g);
c=(g/pakstudies)*100;
printf("\n\t %.3f",c);
if(c<40)
{
printf(" \nu R fail in pakstudies:( ");
getch();
clrscr();
}
else if(c>=40)
{
printf(" \nu R pass in pakstudies:) ");
getch();
clrscr();
}
total=physics+maths+computer+english+urdu+pakstudies;
obt=a+b+d+e+f+g;
avg=obt/6;
printf("Average of marks is : %.3f",avg);
percentage=(obt*100)/total;
printf(" \nPercentage of marks is : %.2f",percentage);
if(percentage>=90)
{
printf(" \n::::::::::::::::::::::::::::::::::::::::");
printf(" \n\tyour grade is:A");
printf(" \n\tcongratulations:) you scored A grade in your exams");
printf(" \n=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-==-=");
}
else if(percentage>=80)
{printf(" \n---------------------------------------");
printf(" \n\tYOur grade is:B");
printf(" \n\tYou have passsed the exams");
printf(" \n---------------------------------------");
}
else if(percentage>=70)
{printf(" \n---------------------------------------------------------");
printf(" \n\tyour grade is:C");
printf(" \n\tYou have passed the exams");
printf(" \n--------------------------------------------------------");
} else if(percentage>=60)
{
printf(" \n-----------------------------------------------------------");
printf(" \n\tYour grade is:D");
printf(" \n\tYou have passed the exams");
printf(" \n------------------------------------------------------------");
}
else if(percentage<60)
{
printf(" \n----------------------------------------------------------------------------------------");
printf(" \n\tYour grade is:F");
printf(" \n\tI Am sorry but you are fail");
printf(" \n----------------------------------------------------------------------------------------");
}
printf(" \n******************************");
printf("\ntotal MArks \t OBtained marks");
printf("\n %.1f",physics,"\t %.1f",a);
printf("\n %.1f",maths,"\t %.1f", b);
printf("\n %.1f",computer,"\t %.1f",d);
printf("\n %.1f",english,"\t %.1f",e);
printf("\n %.1f",urdu,"\t %.1f",f);
printf("\n %.1f",pakstudies,g);
printf(" \n**************************");
getch();
}
推荐答案
您的printf格式错误:
printf("\ n%.1f",physics,"\ t%.1f",a);
需要成为
printf("\ n%.1f \ t%.1f",physics,a);
您只有一个格式字符串,然后是要替换的变量列表.
The format of your printf is wrong:
printf("\n %.1f",physics,"\t %.1f",a);
Needs to be
printf("\n %.1f\t %.1f",physics, a);
You only have one format string and then a list of the vriables you are substituting in .
一些建议:
- 使用有意义的变量名; a,b,c,d等无用且易于误用.
- 在打印的邮件中使用正确的英语(甚至是乌尔都语).像"ur"这样的隐秘''txtspk''使事情变得更难以理解.
- 正确缩进代码,以便您可以轻松看到代码各部分的边界. /li>
- 使用函数来执行重复性任务,例如显示消息和返回值.
- 学习使用调试器单步执行代码并检查其是否在正确的地方执行了正确的操作时间.
Some suggestions:
- Use meaningful variable names; a,b,c,d etc are useless and easy to misuse.
- Use proper English (or even Urdu) in your printed messages. Cryptic ''txtspk'' like "u r" makes things more difficult to understand.
- Indent your code properly so you can easily see the boundaries of each part of the code.
- Use functions for repetitive tasks such as displaying a message and returning a value.
- Learn to use the debugger to step through the code and check that it is doing the right things at the right time.
这篇关于你好!世界C程序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文