xcode - How to initialize array with object in c++ by user input? -


i have code below, credit , load saves object code , title takes first letter of string. tried course[noofcourses_].setcode(code) @ first, gives me error:

cannot initialize parameter type char lvalue char[7].

another problem input skips input prompt title , goes directly credit prompt.

void addcourse() {     course*course=new course[max_no_recs];     char code[max_coursecode_len];     char title[20];     int credit;     int load;      cout << "course code: ";     cin.clear();     cin >> code;     cin.clear();     course[noofcourses_].setcode(code[0]);     cin.clear();     cout << "course title: ";     cin.getline(title, 20);     cin.clear();     course[noofcourses_].settitle(title[0]);     cin.clear();     cout << "credits: ";     cin >> credit;     course[noofcourses_].setcredits(credit);      cout << "study load: ";     cin >> load;     course[noofcourses_].setload(load);     noofcourses_++;      courselist_[noofcourses_]=course; } 

your first way right. should use course[noofcourses_].setcode(code) (by way: better if variable code not start capital letter).

the problem in cource::setcode function. seems parameter char. fix it, should change char*

void cource::setcode(char* code) { ... } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -