# robot step sizes

• 04-29-2004
n00by
robot step sizes
hi again. i have a question on how to get my program to work. my program is to see how many steps a robot can take to get to a certain distance. the user inputs 3 step sizes and the distance. then, my program states how many possible ways the robot can travel the distance. for example, distance is 7. step sizes are 2,3,5. there are 5 possible ways to cover the distance (2+2+3,2+3+2,3+2+2,2+5,5+2).
now my question is how can i fix my recursive functions to work. how can i get the values of the step sizes into the recursive function. here is the code...

Code:

```#include <stdio.h> int steps(int dist); main() {   int a,b,c,d,e;   do     {       printf("Input small step: ");       scanf("%d", &a);       printf("Input medium step: ");       scanf("%d", &b);       printf("Input large step: ");       scanf("%d", &c);       if(a<=0||b<=0||c<=0||a>=b||a>=c||b>=c)         printf("\nIllegal input! Please enter value again!\n\n");     }   while (a>=b||a>=c||b>=c||a<=0||b<=0||c<=0);   do     {       printf("Input total distance to travel: ");       scanf("%d", &d);     }   while (d<=0);   printf("\nNumber of ways the robot can make the trip: %d\n", steps(d)); } int steps(int dist) {   if(dist <= 2)     return dist;   return steps(dist-a) + steps(dist-b) + steps(dist-c); }```
• 04-29-2004
dredre
that's a huge if statement. Try using switch()
• 04-29-2004
linuxdude
nothing wrong with that if statement.
Code:

```  do     {       printf("Input total distance to travel: ");       scanf("%d", &d);     }   while (d<=0);```
you rewrite over d until the last time that is what will mess you up. Once you fix that you could go through the array of d's until '\0'