+ 1

Problem with a code (newbie)

i wrote this program to collect students marks and names , the problem is , when i run it it skips the name typing part ( getline(cin, name) ) , here's the code : #include <iostream> #include <string> using namespace std; int main() { float m[6]; int r; int x,a=1; string n[6]; string name; while(a==1) { cout << "Enter the student's number : " << endl; cin >> r ; cout << "\nType his full name : " << endl; getline(cin, name) ; n[r] = name ; cout << "\nType in his mark : " << endl; cin >> m[r] ; cout << "\n \n The student number : " <<r<< "\n Name : " << n[r] <<"\n Mark : " << m[r] << endl; cout <<"Enter another student's mark ? \n 1-Yes \n 2-No " << endl; cin >> a ; } cout << "The classroom's Marks are : " << endl; for (x=0;x<6;x++) { cout << n[x] << " NR : "<<x<<" Mark : " <<m[x]<< endl; } return.0; }

17th Dec 2018, 12:39 PM
SIMO
SIMO - avatar
4 Answers
+ 2
This has happened to me before, not on Code::Blocks, but still. I circumvented it by reading input with cin and then adding a cin.ignore() below it. Hope this helps.
17th Dec 2018, 7:17 PM
Dread
Dread - avatar
+ 1
Just taking a wild guess without looking, are you splitting your input into multiple lines? If not, that may be why. SoloLearn requires you split multiple inputs into multiple lines.
17th Dec 2018, 12:44 PM
Dread
Dread - avatar
0
I'm running it on code blocks
17th Dec 2018, 1:07 PM
SIMO
SIMO - avatar
0
I replaced the (getline(cin, name)) by cin >> n[r] to directly assign the string to the n array and it worked it gave me the option to write but only words when i wrote 2 words or more . The program skips all the other inputs . I don't know what caused this . But i think shouldn't have used both a string and integer array in the same function .
17th Dec 2018, 10:26 PM
SIMO
SIMO - avatar