Relative grading

#include<iostream.h>
#include<stdio.h>
#include<math.h>
#include<string.h>

struct student_record
{
char name[40];
int roll_no;
int marks;
char grade[2];
};

double round(double a)
{
return floor(a+0.5);
}

void main()
{
student_record s[40];
double a,r,t,u,v,b,c,d,e,f,g,h;
int tmp;
char temp1[40];

for(int i=0; i<10; i++)
{
cout<<"Enter name ";
gets(s[i].name);
cout<<"Enter roll number ";
cin>>s[i].roll_no;
cout<<"enter marks";
cin>>s[i].marks;
cout<<endl;
}

for(i=0; i<=39; i++)
{
for(int j=i+1; j<=39; j++)
{
if(s[i].marks<s[j].marks)
{
tmp = s[i].marks;
s[i].marks = s[j].marks;
s[j].marks = tmp;

tmp = s[i].roll_no;
s[i].roll_no = s[j].roll_no;
s[j].roll_no = tmp;

strcpy(temp,s[i].name);
strcpy(s[i].name,s[j].name);
strcpy(s[j].name,temp);*/
}
}

}
a = ((15*40)/100);
a = int (a+0.5)

r = round((20*40)/100);
t = round((8*40)/100);
u = round((4*40)/100);
v = round((3*40)/100);

b = a+a;
c = b+r;
d = c+r;
e = d+a;
f = e+t;
g = f+u;
h = g+v;

for(i=0; i<40; i++)
{
strcpy(s[i].grade," ");
}

for(i=0; i<40; i++)
{
if(i<a)
strcpy(s[i].grade,"A ");
else if(i<b)
strcpy(s[i].grade,"B+");
else if(i<c)
strcpy(s[i].grade,"B ");
else if(i<d)
strcpy(s[i].grade,"C+");
else if(i<e)
strcpy(s[i].grade,"C ");
else if(i<f)
strcpy(s[i].grade,"D+");
else if(i<g)
strcpy(s[i].grade,"D ");
else if(i<h)
strcpy(s[i].grade,"F ");
}
cout<<"Name\t\t Roll number\t Marks\t grade"<<endl;


for(i = 0; i<40; i++)
{
cout<<s[i].name<<"\t"<<s[i].roll_no<<"\t"<<s[i].marks<<"\t"<<s[i].grade<<"\t"<<endl;
}
}
please use variables with a name, not just single letters. no one will know what the purpose is.

use switch instead of if else if else if ....

and what is your problem? you did just copy paste your code here
Topic archived. No new replies allowed.