I just started to program in C and I found a problem when running the program.
The error is the following,resto == a % b;
[Error] invalid operands of types 'float' and 'float' to binary 'operator%' in C
#include<stdio.h>
#include <math.h>
char n;
int main (){
printf ("Programma che svolge ogni tipo di operazione aritmetica tra 2 numeri a e b\n'n' per chiudere\nPremere 'invio' per continuare\n");
float a, b, somma, differenza, prodotto, quoziente;
int resto;
while (n=getchar()!='n'){
printf ("Inserisci a\n");
scanf ("%f",&a);
printf ("Inserisci b\n");
scanf ("%f",&b);
somma = a + b;
differenza = a - b;
prodotto = a * b;
quoziente = a / b;
resto = a % b;
printf ("somma = %f + %f = %f\n",a,b,somma);
printf ("differenza = %f - %f = %f\n",a,b,differenza);
printf ("prodotto = %f * %f = %f\n",a,b,prodotto);
printf ("quoziente = %f / %f = %f\n",a,b,quoziente);
printf ("resto = %f %% %f = %d\n",a,b,resto);
}
return 0;
}
The solution there:
