switch-case
only works with constant values(*) (such as 3
or 'a'
), not with ranges (such as <=100
). You also must not include the variable name in the case
statement. Correct syntax would be as follows:
switch (Essais)
{
case 1:
/* ... */
break;
case 2:
/* ... */
break;
default:
/* ... */
}
If you need range tests, use if
instead of switch-case
:
if (Essais <= 80)
return "Cote";
else if (Essais <= 100)
return "Muvais";
Also note that you can't use single quotation marks '
for strings. Use double quotation marks "
instead, and use variables of type std::string
(not char
) to store strings.
(*) To be precise, the condition given in the case
statements must be a constant expression of integral type, enumeration type, or class type convertible to integer or enumeration type (see §6.4.2/2 of the C++ Standard for details).