error in code

hi ..I have made this program... the user needs to enter the name of the student and the registeration number...and his marks get stored..
after the data of the first student get feeded...the control jumps directly to the registeration number part...without actually making the user enter the name of the second student..the code is given below..can anyone spot the error.



#include<iostream>
#include<string.h>
using namespace std;

class student_info
{
char name[20];
char roll_no[20];
public:
void get_info();
void show_info();
};

void student_info::get_info()
{

cout<<endl<<"Enter name of student:";
cin.getline(name,20); // *problem
cout<<endl;
cout<<"Enter student Roll number:";
cin>>roll_no;
}

void student_info::show_info()
{
cout<<endl<<"Student Name:";
cout<<name<<endl;
cout<<"Roll Number:";
cout<<roll_no<<endl;
}


class student_marks:public student_info
{
int math,eng,chem,phy,pdu,total;
float percent;
public:
void get_marks(int, int, int, int,int);
void show_marks();
};

void student_marks::get_marks(int m1, int m2, int m3, int m4,int m5)
{
math = m1;
eng = m2;
chem = m3;
phy = m4;
pdu = m5;
total = math + eng + chem + phy + pdu;
percent = float(((total*100)/500));
cout<<endl;
}

void student_marks::show_marks()
{
cout<<endl;
cout<<"Student Marks:"<<endl;
cout<<"MATH:"<<math<<endl;
cout<<"ENGLISH:"<<eng<<endl;
cout<<"CHEMISTRY:"<<chem<<endl;
cout<<"PHYSICS:"<<phy<<endl;
cout<<"GRAND TOTAL:"<<total<<endl;
cout<<"PERCENTAGE SECURED:"<<percent<<"%"<<endl;
}

class student_report: public student_marks
{
public:
void display();
};

void student_report::display()
{
cout<<endl<<"The student details are:"<<endl;
show_info();
show_marks();
}

int main()
{

//class student_report mirror[3];
student_report *mirror;
mirror=new student_report[3];
for(int i = 0; i<3; i++)
{
cout<<endl;
mirror[i].get_info();

mirror[i].get_marks(73+i,88,67+i,68+2*i,81-4*i);
mirror[i].display();
cout<<endl;
}
cout<<endl;
system("pause");
return 0;
}


i have commented the part where I enter the name.thanks
the user needs to enter the name of the student and the registeration number...and his marks get stored..
after the data of the first student get feeded...the control jumps directly to the registeration number part...without actually making the user enter the name of the second student
That's because you call:
get_info()
get_marks()
display()
for each user.

Also, in get_marks(), you have:
 
percent = float(((total*100)/500));
Do you realise this performs integer multiplication and division yielding a truncated result?

Topic archived. No new replies allowed.