char function

Hello.
I have a school project, and I am not allowed to use global int.
Do you guys think I can use char function?
How does the char works anyway?

Is this a wind up?

I'm pretty new at this, so I'm not sure. But you can look at a small piece of my code where I used char:

char bestem(){
int leftDistance, rightDistance, centerDistance;
//mulighet 1
seRundt();
if(leftDistance>rightDistance && leftDistance>centerDistance){
valg = '1';
}
//mulighet 2
else if (rightDistance>leftDistance && rightDistance>centerDistance){
valg = '2';
}
//mulighet 3
else {
valg = '3';
}
return valg;
}

And at the top of my code I have the 'char valg' witch I return the "value" to :smiley:

NoBe92:
I'm pretty new at this, so I'm not sure. But you can look at a small piece of my code where I used char:

char bestem(){
int leftDistance, rightDistance, centerDistance;
//mulighet 1
seRundt();
if(leftDistance>rightDistance && leftDistance>centerDistance){
valg = '1';
}
//mulighet 2
else if (rightDistance>leftDistance && rightDistance>centerDistance){
valg = '2';
}
//mulighet 3
else {
valg = '3';
}
return valg;
}

And at the top of my code I have the 'char valg' witch I return the "value" to :smiley:

So why make valg a global variable? Since your function returns a value, you can use that. you don't need a global variable.

Okay, thank you. :slight_smile: