This little bit of C code is driving me nuts. It asks for the Input Voltage but then it skips Resistor 1 and asks for Resistor 2. I’m missing something extremely obvious here… What the heck is going on…
#include <stdio.h>
int main()
{
float Vin;
int R1;
int R2;
printf("Input Voltage: ");
scanf("%.3f", &Vin);
printf("\nResistor 1: ");
scanf("%d", &R1);
printf("\nResistor 2: ");
scanf("%d", &R2);
return(0);
}
Remove the
.3part:It does not really make sense to configure the number of decimal digits for input 🙂 Therefore,
scanfdoes not support it. Afloatalways has 8 decimal digits. Crank up your compiler’s warning levels.