You can replace ‘color = getColor()’ with ‘color = to_string(getColor())’, but probably you want to return a string instead of number from getColor().
Or use int instead of string for color variables (in several places).
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
You can replace ‘color = getColor()’ with ‘color = to_string(getColor())’, but probably you want to return a string instead of number from getColor().
Or use int instead of string for color variables (in several places).
You may be confusing yourself because you are using
the same name for both the numeric (int) color value
and the alpha (string) name of the color. If you think
about the code you have written such as this:
cin >> color;
if (color == 1)
{
cout << blue;
color = 1;
};
it should be apparent that something isn't quite right.
If color is equal to 1, what sense does it make to set
it to 1 - the value that it already holds? As Viorel_
suggested, you are not keeping distinct the places
that you want to use a number to represent the color
and the places where you want the name of the color.