#what is wrong with this code?

3 messages · Page 1 of 1 (latest)

barren herald
#

#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct Course {
string courseCode;
int creditHours;
string section;
};

vector<Course> courses;

bool isEnrolled(string studentID, string courseCode) {
for (Course course : courses) {
if (course.courseCode == courseCode) {
return true;
}
}
return false;
}

void enrollStudent() {
string studentID;
cout ​oaicite:{"index":2,"invalid_reason":"Malformed citation << \"Enter student ID: \";\n cin >>"}​ studentID;

cout << "Courses offered: " << endl;
cout << "Code\tCredits\tSection" << endl;
cout << "----------------------------" << endl;
// display list of subjects with credit hours offered

string courseCode;
int creditHours;
string section;
cout &#8203;`oaicite:{"index":3,"invalid_reason":"Malformed citation << \"Enter course code: \";\n    cin >>"}`&#8203; courseCode;
if (isEnrolled(studentID, courseCode)) {
    cout << "Error: student is already enrolled in this course." << endl;
} else {
    // get credit hours and section for chosen course
    cout &#8203;`oaicite:{"index":4,"invalid_reason":"Malformed citation << \"Enter credit hours: \";\n        cin >>"}`&#8203; creditHours;
    cout &#8203;`oaicite:{"index":5,"invalid_reason":"Malformed citation << \"Enter section: \";\n        cin >>"}`&#8203; section;

    // add course to array
    Course course;
    course.courseCode = courseCode;
    course.creditHours = creditHours;
    course.section = section;
    courses.push_back(course);
}

}

int main() {
enrollStudent();
return 0;
}

steep sluice
#

The issue with this code is that the cout statements in lines 12, 15, 18, 21, and 24 are missing the insertion operator (<<) before the string being output. They should be written as "cout << "Enter student ID: ";" instead of "cout ​0
Invalid citation
oaicite:{"index":0,"invalid_reason":"Malformed citation << "Enter student ID: ";\n cin >>"}​"}​ studentID;". The same applies to the other similar lines. This will prevent a compilation error and allow the program to run properly.

#

@barren herald