I am trying to make a code in which the user enters a number and through the system (color) command can change the color. I already tried to change the variables to char, string, (I do not know if I was doing it right), and they give me errors related to the types of variables. When it manages to work, what happens is that the characters are running, if I enter the number two, I will "lor" instead of "color" This is the code:
#include <iostream>
#include <cstdlib>
#include <string>
int opcion;
using namespace std;
int main()
{
int seleccion;
char color[20];
do {
cout<<"\n 1. Cambiar color "<<endl<<" 2. Salir"<<endl<<"\n Seleccione una opcion: ";
cin>>opcion;
switch(opcion){
case 1: {
cout<<"\n\t - CAMBIAR COLOR - ";
cout<<"\n 0. Negro"<<endl<<" 1. Azul"<<endl<<" 2. Verde"<<endl<<" 3. Aguamarina"<<endl<<" 4. Rojo"<<endl<<" 5. Purpura"<<endl<<" 6. Amarillo"<<endl<<" 7. Blanco"<<endl<<" 8. Gris"<<endl<<" 9. Azul claro"<<endl;
cout<<"\n Ingrese el color que desea: ";
cin>>seleccion;
seleccion = itoa(seleccion.c_str());
color[20]="color "+seleccion;
system(color);
break;
}
case 2:
cout<<"\n Aplicacion finalizada! "<<endl;
break;
default:
cout<<"\n Opcion incorrecta!!";
break;
}
} while (opcion!=2);
}
I would appreciate an answer.