Hi, while I know homework questions are shunned upon, I have been struggling for the past few days. With my code, I'm supposed to enter 5 grades using a for loop and calculate the average of the grades. But when I run the code I have, it doesn't allow me to input 5 grades. Here's my code. When I run it, it just outputs this: "Enter Grade 1: Enter Grade 2: Enter Grade 3: Enter Grade 4: Enter Grade 5:" and doesn't actually allow me to enter any grades. I am a complete beginner at coding so I might just be missing something crucial in my code.
You didn't say what you were inputting as your studentName.
Since the prompt says "First and Last name", I assume you're typing something like "John Smith". The issue with this is that cin's >> operator is whitespace-delimited, so it only reads in the first word (John), leaving Smith still in the buffer, which then causes the next cin >> command to fail to parse an int.
instead of cin >> studentName;
you want getline(cin, studentName);