Is there any way to endl on cin?

630 Views Asked by At

I need endl on cin "name" as there may be 2 words on input "name"

cout << "Enter your name:           ";
cin  >> name;
cout << "Enter your student ID:     ";
cin  >> StuID;

cout << endl << "Please enter four number.";
cout << endl << "Enter the 1st number:      ";
cin  >> FN;
cout << "Enter the 2nd number:      ";
cin  >> SN;
cout << "Enter the 3rd number:      ";
cin  >> TN;
cout << "Enter the 4th number:      ";
cin  >> FourthN;

total = FN + SN + TN + FourthN;
avg = total / 4;

cout << endl <<"---------------------------------Output----------------------------------" << endl << endl;
cout << "Student Name:              " << name  << endl;
cout << "Student ID:                " << StuID  << endl;
cout << "Total:                     " << FN <<" + " << SN << " + " << TN << " + " << FourthN << " = " << total << endl;
cout << "Average Number:            " << avg;
cout << endl << endl <<"---------------------------------Output----------------------------------" << endl << endl;

return 0;

and somehow the compiler just jump to line "enter the first number" and did not run the coding line of student ID input.

1

There are 1 best solutions below

0
On

Try:

string fullName;
cout << "Type your full name: ";
getline (cin, fullName);
cout << "Your name is: " << fullName;