I have to make a program that when the user introduces a number clasificates it in positive y negative and if the user inserts a ',' it change to a '.'. Actually it only accept positive numbers but no negatives and decimals I have te following code and i have to do it with "switch" estructure:
int main()
{
int p=0,n=0,k=0;
float positivos[p] = {},negativos[n] = {};
float valor, SumaPositivos=0, SumaNegativos=0,prueba=0;
char caracter;
std::cout.setf(std::ios::fixed);
std::cout.setf(std::ios::showpoint);
std::cout.setf(std::ios::showpos);
std::cout.precision(2);
cout << "Introduce your money movemente: " ;
while (valor!=0)
{
cin.get(caracter);
switch(caracter)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
prueba=prueba*10+float(caracter-'0');
valor=prueba;
break;
case '\n':
if(prueba>0){
positivos[p] = prueba;
SumaPositivos+=prueba;
p++;
std::cout << prueba << "\n";
}
else{
negativos[n] = prueba;
SumaNegativos+=prueba;
n++;
std::cout << prueba << "\n";
}
prueba=0;
break;
default:
{
cout << "No valid character, insert numbers.";
prueba=0;
caracter=' ';
}
}
}
}