There are a few errors in this which i cant find out. Could you please help me?
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main ()
{clrscr();
int p[10],c[10],m[10],t[10],r[10];
float a[10];
char op;
for(int i=0;i<10;i++)
{cout << "Please enter the roll number of student: " << (i+1) << ": " ;
cin >> r[i];
cout << "\nPlease enter the mark in Physics: ";
cin >> p[i];
cout << "\nPlease enter the mark in Chemistry: ";
cin >> c[i];
cout << "\nPlease enter the mark in Maths: ";
cin >> m[i];
t[i]=p[i]+c[i]+m[i];
a[i]=t[i]/3.0;
clrscr();
}
cout << "\n\n";
cout << "Roll No\t\tPhysics\t\tChemistry\t\tMaths\t\tTotal\t\tAverage";
for(i=0;i<10;i++)
{cout << r[i]<<"\t\t "<<p[i]<<"\t\t "<<c[i]<<"\t\t "<<m[i]<<"\t\t "<<t[i]<<"\t\t "<<a[i]<<"\n";
}
getch();
clrscr();
cout << "To display:-\n";
cout << "1.The student who got the highest total\n";
cout << "2.The student who got the highest in any subject\n";
cout << "3.The details of the student\n\n";
cout << "Please enter your choice of option: ";
cin >> op;
if(op=='1')
{int gr;
gr=t[0];
int pos;
for(i=0;i<10;i++)
{if(t[i]>gr)
{gr=t[i];
pos=i;
}
}
cout << "The student who scored the highest is: " << r[pos] ;
cout << "\nScore is: " << gr;
}
else
{if(op=='2')
{char sub,ans='y';
cout << "1.Physics";
cout << "2.Chemistry";
cout << "3.Maths";
while(tolower(ans)=='y')
{cout << "Enter the subject required: ";
cin >> sub;
if(sub=='1')
{int gr=p[0],pos;
for(i=0;i<10;i++)
{if(p[i]>gr)
{gr=p[i];
pos=i;
}
}
cout << "The student who scored the highest in Physics is: " << r[pos];
cout << "\nScore is: " << gr;
}
else
{if(sub=='2')
{int gr=c[0],pos;
for(i=0;i<10;i++)
{if(c[i]>gr)
{gr=c[i];
pos=i;
}
}
cout << "The student who scored the highest in Chemistry is: " << r[pos];
cout << "\nScore is: " << gr;
}
else
{if(sub=='3')
{int gr=m[0],pos;
for(i=0;i<10;i++)
{if(m[i]>gr)
{gr=m[i];
pos=i;
}
}
cout << "The student who scored the highest in Maths is: " << r[pos];
cout << "\nScore is: " << gr;
}
else
{cout << "Invalid choice. Try again";
}
}
}
cout << "Would you like to view an other subject: ";
cin >> ans;
}
}
else
{if(op=='3')
int n;
char ans='y';
while (ans=='y')
{cout << "Please enter the roll number: ";
cin >> n;
for(i=0;i<10;i++)
{if(n=r[i])
{cout << "Roll Number is: " << r[i];
cout << "\nPhysics: " << p[i];
cout << "\nChemistry: " << c[i];
cout << "\nMaths: " << m[i];
cout << "\nTotal: " << t[i];
cout << "\nAverage: " << a[i];
}
else
{cout << "Invalid Roll Number. Try again";
}
}
cout << "Would you like to view again?";
cin >> ans;
}
}
}
}
Last edited on
enclose your code in [code ] tags and provide us with the line # in which your compiler says there are errors? This is a bit of a headache to look at.