what's wrong with it? please help
Hi
This code was working fine until I made some changes to it. Now it doesn't display the name. Below is given output for the student #1, you can see it doesn't display the entered name. It leaves it blank. What's the reason in your view? Please help me with it.
Code:
// student_data_read_practice.cpp
// program which reads data of some students
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
using namespace std;
/////////////////////////////////////////////////////
struct Date {int d; string m; int y;};
////////////////////////////////////////////////////
/////////////////////////////////////////////////////
struct Student {int rollno; string sex; string name; float gpa; Date DoB;};
/////////////////////////////////////////////////////
Student read();
void prnt(Student dummystud);
char grade(float dummyGpa);
int main()
{
Student stud[5];
for(int i=0; i<5; i++)
{
cout << "enter student #" << (i+1) << "'s details below:-" << endl;
stud[i] = read();
prnt(stud[i]);
cout << endl << endl;
}
system("pause");
return 0;
}
//-----------------------------------------------
// Student read() definition
Student read()
{
Student stud; string name;
cout << "enter name: "; getline(cin, name);
cout << "enter roll number: "; cin >> stud.rollno;
cout << "enter sex: "; cin >> stud.sex;
cout << "enter date of birth (e.g. 01 Jan 2000) below:-" << endl;
cout << "enter day: "; cin >> stud.DoB.d;
cout << "enter month: "; cin >> stud.DoB.m;
cout << "enter year: "; cin >> stud.DoB.y;
cout << "enter GPA: "; cin >> stud.gpa;
cin.ignore();
return stud;
}
//-------------------------------------------------
// void prnt() definition
void prnt (Student dummystud)
{
cout << "\n\n\n************************************\n\n\n";
cout << "roll no.: " << dummystud.rollno << endl;
cout << "name: " << dummystud.name << endl;
cout << "sex: " << dummystud.sex << endl;
cout << "date of birth: " << dummystud.DoB.d << "-" << dummystud.DoB.m << "-" << dummystud.DoB.y << endl;
cout << "grade: " << grade(dummystud.gpa) << endl;
cout << "\n\n\n************************************";
}
//-------------------------------------------------------------
// grade() definition
char grade(float dummyGpa)
{
if (dummyGpa >= 3.5)
return 'A';
else if (dummyGpa >= 3.0)
return 'B';
else if (dummyGpa >= 2.0)
return 'C';
else
return 'D';
}
//----------------------------------------------------
OUTPUT:
Code:
enter student #1's details below:-
enter name: jackson heights
enter roll number: 201
enter sex: male
enter date of birth (e.g. 01 Jan 2000) below:-
enter day: 01
enter month: 01
enter year: 1900
enter GPA: 5
************************************
roll no.: 201
name:
sex: male
date of birth: 1-01-1900
grade: A
************************************
enter student #2's details below:-
enter name: