how to code a result table by allowing the user to enter the courses and all marks for the courses

<
#include <iostream>
#include <string>

using namespace std;

int main()
{
int j1,j2,j3;
int o1,o2,o3;
int s1,s2,s3;
int h1,h2,h3;
int u1,u2,u3;
int a1,a2,a3;
string courses;

cout<< "\n enter course 1 "<<endl;
getline(cin, courses);
cout<< "class marks"<<endl;
cin>> j1;
cout<< "mid-sem marks"<<endl;
cin>> j2;
cout<< "end of sem marks"<<endl;
cin>> j3;

cout<< "\n enter course 2 "<<endl;
getline(cin, courses);
cout<< "class marks"<<endl;
cin>> o1;
cout<< "mid-sem marks"<<endl;
cin>> o2;
cout<< "end of sem marks"<<endl;
cin>> o3;

cout<< "\n enter course 3 "<<endl;
getline(cin, courses);
cout<< "class marks"<<endl;
cin>> s1;
cout<< "mid-sem marks"<<endl;
cin>> s2;
cout<< "end of sem marks"<<endl;
cin>> s3;

cout<< "\n enter course 4 "<<endl;
getline(cin, courses);
cout<< "class marks"<<endl;
cin>> h1;
cout<< "mid-sem marks"<<endl;
cin>> h2;
cout<< "end of sem marks"<<endl;
cin>> h3;

cout<< " \n enter course 5 "<<endl;
getline(cin, courses);
cout<< "class marks"<<endl;
cin>> u1;
cout<< "mid-sem marks"<<endl;
cin>> u2;
cout<< "end of sem marks"<<endl;
cin>> u3;

cout<< " \n enter course 6 "<<endl;
getline(cin, courses);
cout<< "class marks"<<endl;
cin>> a1;
cout<< "mid-sem marks"<<endl;
cin>> a2;
cout<< "end of sem marks"<<endl;
cin>> a3;

cout<< "\n \n COURSES - CLASS MARKS - MID-SEM MARKS - END OF SEM MARKS - TOTAL MARKS - GRADES \n "<<endl;

} >
Last edited on
You need to lean how to use arrays and loops.
http://www.cplusplus.com/doc/tutorial/arrays/
http://www.cplusplus.com/doc/tutorial/control/

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>

using namespace 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
}

Last edited on
thanks alot
but please i tried running it and i had an error at line 19
i have solving it but didnt work and i dint know why an error occured
i dint know why an error occurred

What error?
Topic archived. No new replies allowed.