I have an assignment that requires me to write a program that prompts the user to enter the name of a student and their grade and keeps looping until they enter "quit".
But I can't figure out how to get the user input for the array to get the entire line (which is a first & last name so I can't just do cin >> name1[i] since theres white space) but when I use cin.getline or just getline and compile it, I get an error message saying No member function matching getline.
Also when I compile it without getline, its just a continuous loop and doesnt let me input any info for name or grade. I'm new to arrays and cstring so please try to dumb down where I'm messing up. Thank you.
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>
using namespace std;
int main() {
const int CAPACITY = 50;
string name1[CAPACITY];
string grade[CAPACITY];
char quit[]= "quit";
int i;
//for loop to get names and grades from user until quit is entered
for (i = 0; i < CAPACITY; i++) {
while (name1[i] != quit)
cout << "Please input a name (or 'quit' to quit): ";
getline(cin, name1[i]);
//break if name1[i] = quit
if (name1[i].compare(quit) == 0) {
break;
}
//continue loop if quit not entered and get the grade from that person
cout << "Please input this person's grade: ";
cin >> grade[i];
}
return 0;
}