Char function

Hello i have a question.
It is possoble in c++ to return a char variable?

for example
1
2
3
4
5
6
7
8
9
10
11
12
char Check(S, n, a){
char OK;
for(int i=0; i<n; i++){
if(something == a){
OK = 'T';
}
else{
OK = 'F';
}
}
return OK;
}
Last edited on
Yes, but if you want this to compile you need to assign 'S', 'n' and 'a' a variable type and declare something.

When you find yourself wanting to ask a question like this, don't. Just compile it and see what happens.
Thanks, I have one more question
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void Maxi2(Skl S[], int n){
	double max = 0.0;
	double max2 = 0.0;
	int ind;
	int ind2=0;
	char skl;
	char skl2 = ' ' ;
	for(int i=0; i<n; i++){
		if(S[i].GetS()>max){
			max2=max;
			ind = i;
			max = S[i].GetS();
			skl = S[i].GetAdress();
		}else if(S[i].GetS() > max2){
			max2 = S[i].GetS();
			ind2 = i;
			skl2 = S[i].GetAdress();
		}
	}
}

And why my program just break when i try to max2=Gets()???
"Gets()" appears to be a member function of the "Skl" data type so you can't use it as a stand alone function.
I dont get it so how it should be written? By the way Skl is my variable so Skl is not a function.
By the way Skl is my variable so Skl is not a function.


Correct, like I said, it is a data type. The member function of that data type is usually only relevant to a specific instance of that data type.

Unfortunately my crystal ball is broken again, so I can not magically see the code that you wrote for the "Skl" data type and therefore cannot tell you how it should be written nor can I see into your thoughts to tell what it is you are trying to accomplish. If you could post this code along with a brief explanation of what it is you're trying to do then I may be able to help you further.
OK, sorry :)
Here is my class
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Skl{
private:
	double s; 
	char adr; // adress
	int n; 
public:
	Sklypas():s(0.0), adr (), n(0) {}
	Sklypas(double s, char adr, int n):
		s(s), adr(adr), n(n) {}
	void SetS(double s);
	void GetAdress(char adr);
	void SetiN(int n);
	double GetS() {return s;}
	char GetAdress() {return adr;}
	int GetN() {return n;}
};

void Skl::SetS(double s){
	Skl::s = s;
}
void Skl::SetAdress(char adr){
	Skl::adr = adr;
}
void Skl::SetN(int n){
	Skl::n = n;
}

void Maxi2(Skl S[], int n){
	double max = 0.0;
	double max2 = 0.0;
	int ind;
	int ind2=0;
	char skl;
	char skl2 = ' ' ;
	for(int i=0; i<n; i++){
		if(S[i].GetS()>max){
			max2=max;
			ind = i;
			max = S[i].GetS();
			skl = S[i].GetAdress();
		}else if(S[i].GetS() > max2){
			max2 = S[i].GetS();
			ind2 = i;
			skl2 = S[i].GetAdress();
		}
	}
}
What kind of limit do you want 'max' and 'max2' to designate?
Topic archived. No new replies allowed.