Each time you do a getline of courses, you're overlaying the previous value.
It's not a good idea to switch between getline() and the extraction operator >>.
The extraction operator >> leaves the new line character in the stream which getline() will retrieve and then consider the operation complete.
So what you need to do is to consume that new line character before you try to retrieve the string.
One way is to use the istream.ignore() function to empty the input buffer.
See http://www.cplusplus.com/reference/istream/istream/ignore/ for more information.
PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
#include <iostream>
#include <string>
usingnamespace std;
struct course_info
{
string course_name;
int marks[3];
};
int main()
{
course_info info[6];
for (int i = 0; i < 6; i++)
{
cout << "\n enter course " << i + 1 << endl;
getline(cin, courses);
cin.ignore(100);
cout << "class marks" << endl;
cin >> info[i].marks[0];
cout << "mid-sem marks" << endl;
cin >> info[i].marks[1];
cout << "end of sem marks" << endl;
cin >> info[i].marks[2];
}
cout << "\n \n COURSES - CLASS MARKS - MID-SEM MARKS - END OF SEM MARKS - TOTAL MARKS - GRADES \n " << endl;
// Now you can print out the data from the array
}