max is an integer with value 7
temp is a character with value '7'
The value '7' corresponds to the value 55 in the ASCII. (google ASCII for details)
therefore the loop will not break when max is the character '7' but when the value of the character is 7
1 2 3 4 5 6 7 8
//string second="45670";
//string first="";
//char max='7'; // added ' ', should work now
for(char temp:second)
{
first += temp;
if(temp==max) break; //not working
}
But I'm not sure if I understand what if(temp==(max + '0')) break; does.
in the ASCII all characters have a value.
values for 0-9 are consecutive, so to get the character-value of a number you simply need to add the value of '0' (which is equivalent to 48)