FYI, I declare a Class call UC, inside UC I declare a variables call course
and its a array of [4], this related to the problem that I am facing right now. Go to the line that i comments as problem, all i know for now is that the line for(UC &i :: one.course)
is wrong especially the UC , this line of code should do a forloop of course[4]
but it doesnt, it just show error like i has not been declared
. And my expected output is down there.
#include <iostream>
#include <string>
using namespace std;
class UC{
public:
string name;
int history;
string founder;
string course[4];
};
void print(string, int, string);
int main()
{
UC one;
one.name = "ABC";
one.history = 5;
one.founder = "Mr.Chong";
one.course[0] = "IT";
one.course[1] = "Interior Design";
one.course[2] = "Mass Comm";
one.course[3] = "Business";
print(one.name, one.history, one.founder);
cout<<"Our Course: ";
//problem here//
string delim = "";
for(UC &i :: one.course){
cout<< delim <<i;
delim = ", ";
};
//problem here//
return 0;
}
void print(string r, int x, string y){
cout<<"Our College Name: "<<r<<endl;
cout<<"Our History: "<<x<<endl;
cout<<"Our Founder: "<<y<<endl;
};
I expect the output will be like
Our College Name: ABC
Our History: 5
Our Founder: Mr.Chong
Our Course: IT, Interior Design, Mass Comm, Business
//this line doesnt works