atoi and floating point errors
Hi all! I'm trying to make a really simple program in c which when given 3 values plonks them in a formula and outputs another value.
Here's the code before I get onto the problem
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int wr2;
int fst2;
int rst2;
int gear;
char wr1[5];
char fst1[5];
char rst1[5];
printf("Please enter wheel radius\n");
scanf("%d",wr1);
wr2=atoi(wr1);
printf("Please enter number of teeth on front sprocket\n");
scanf("%d",fst1);
fst2=atoi(fst1);
printf("Please enter number of teeth on rear sprocket\n");
scanf("%d",rst1);
rst2=atoi(rst1);
gear=wr2*(fst2/rst2);
printf("Wheel Radius %d inches, front teeth %d, rear teeth %d gives gear %d inches.\n",wr2,fst2,rst2,gear);
return(0);
}
When run the program stores the 3 values entered and either outputs 1 of 2 things depending on the coding. If gear is set as an int i get a floating point error, is gear is set as float it always outputs 54 no matter what values are entered. Its a really basic error but as I've just started C I cannot figure out why it wont work. Any help is much appreciated.
Native