Here is a small program to request and print some information. The problem point is storing name which may include spaces. My problem is that when reaches Enter your name
it quickly moves to Enter your total marks
without giving user an option to enter the name. Why is this happening?
#include <iostream>
using namespace std;
class StudentInformation {
protected:
int studentID;
string studentName;
int totalMarks;
public:
void input() {
cout << "Enter your student id number: ";
cin >> studentID;
cout << "Enter your name: ";
getline(cin, studentName);
cout << "Enter your total marks";
cin >> totalMarks;
}
void show() {
cout << "Student ID: " << studentID << endl;
cout << "Student Name: " << studentName << endl;
cout << "Total Marks: " << totalMarks << endl;
}
};
int main()
{
cout << "Hello World!" << endl;
StudentInformation stdinfo;
stdinfo.input();
stdinfo.show();
return 0;
}