Buenas. Quisiera que me ayuden con un programa que estoy haciendo. Cuando lo ejecuto me saltan varios errores:
/home/ubuntu/: In function ‘main’:
/home/ubuntu/: error: invalid operands to binary % (have ‘float’ and ‘int’)
unidad = num % 100;
^
/home/ubuntu/workspace: error: invalid operands to binary % (have ‘float’ and ‘int’)
unidad = unidad % 10;
^
/home/ubuntu/workspace/: error: invalid operands to binary % (have ‘float’ and ‘int’)
centena = num % 100;
^
/home/ubuntu/workspace: error: invalid operands to binary % (have ‘float’ and ‘int’)
decena = num % 100;
^
/home/ubuntu/workspace: error: invalid operands to binary % (have ‘float’ and ‘int’)
decena= decena % 10;
^
/home/ubuntu/workspace/: error: invalid operands to binary % (have ‘float’ and ‘int’)
unidad = num % 10;
^
/home/ubuntu/workspace/: error: invalid operands to binary % (have ‘float’ and ‘int’)
decena = num % 10;
^
El programa es el siguiente:
//Programa para ingresar un numero (ENTERO Y POSITIVO) de 3 o 2 digitos y mostrarlo invertido.
#include <stdio.h>
int main (void) {
float num=0;
float unidad=0;
float decena=0;
float centena=0;
float auxiliar=0;
float numero_invertido=0;
printf("Ingrese un numero de 3 o 2 cifras: ");
if ((num>99) && (num<1000)) {
unidad = num % 100;
unidad = unidad % 10;
unidad = unidad * 100;
centena = num % 100;
centena = num - centena;
centena = centena / 100;
decena = num % 100;
auxiliar = decena;
decena= decena % 10;
decena = auxiliar - decena;
numero_invertido = unidad + decena + centena;
printf("El numero invertido es: %f", numero_invertido
);
}
if ((num>9) && (num<100)) {
unidad = num % 10;
unidad = unidad * 10;
decena = num % 10;
decena = num - decena;
decena = decena / 10;
numero_invertido = unidad + decena;
printf("El numero invertido es : %f", numero_invertido
);
}
else {
printf("El numero no cumple las condiciones");
}
return 0;
}
· Los códigos deben ir en etiquetas GeSHi
>aquí las reglas del foro (http://foro.elhacker.net/reglas.htm)
-Engel Lex
te traduzco el error
error: invalid operands to binary % (have ‘float’ and ‘int’)
unidad = num % 100;
error: operandos invalidos a binario % (tienes 'float' e 'int')
es decir el simbolo % no puede ser usado con operadores incompatibles a nivel binario como float e int... el operador % está hecho exclusivamente para enteros