1.#inf00

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cecnik
    New Member
    • Jun 2014
    • 7

    1.#inf00

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    int main()
    {
    float zav_pot1, zav_pot2, v0, a, kt, g, t;
    int x;
    	
    	printf("with this program we will calculate the stoping distance of a car\nwhile taking and not taking in account the reaction time of the driver.\n");
        printf("enter starting speed of the vehicle in km/h:\n");
        scanf("%f", &v0);
        printf("Enter reaction time of the driver in seconds:\n");
        scanf("%f", &t);
        printf("enter road conditions:\n1 dry\n2 wet\n3 icy\n");
        scanf("%d", &x);
        
        switch(x)
        {
                 case(1):
                 kt=0,6;
                 break;
                 case(2):
                 kt=0,3;
                 break;
                 case(3):
                 kt=0,1;
                 break;
                 default:
                 printf("Run program again and ener a valid value!\n");
                 system("pause");
                 return 0;
    }
     
        zav_pot1=(v0*v0)/(2*a);
        zav_pot2=(v0*t)+((v0+v0)/(2*a));
        
        printf("Stoping distance without reaction time is %.f m.\n", zav_pot1);
        printf("Stopping distance with reaction time is %f m.\n", zav_pot2);
        system("PAUSE");	
        
        return 0;
    }
    SO again I have a scool asignment.. if you compile and run the program it works fine with one little problem. The values printed in the last part both show as 1.#INF00. I get that this problem ocures due to insufficient bit room or something like that. I would very much appreciate the help.
    Last edited by Rabbit; Jun 13 '14, 07:53 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code or formatted data.

    You never define a. Which means a can be anything. In this case, a is probably 0. And you can't divide by 0.

    Comment

    • cecnik
      New Member
      • Jun 2014
      • 7

      #3
      thanks, I have to be more precise when writing code.. sory for the post btw, new on the forum and still getting used to it.

      Comment

      • cecnik
        New Member
        • Jun 2014
        • 7

        #4
        ok so I added the line "a=kt*9,81; " just above the line "zav_pot1=(v0*v 0)/(2*a);" but the problem is still there.. I'm sory if it is realy obvious but I just can't see it..

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          That should be fine if the values you are passing in aren't too large. I would look at the values of each variable before the calculations to see what's actually stored in there.

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            Looking at line 21 (for example): "kt=0,6;".
            Is the locale set such that comma (",") serves as the decimal point?

            Comment

            • cecnik
              New Member
              • Jun 2014
              • 7

              #7
              again, my unexperience bites me.. in my country we use commas for decimals, doesnt translate in c unfortunately..
              thanks by the way

              Comment

              • ganesh88
                New Member
                • Jun 2014
                • 2

                #8
                Don't use comas in float...kt=0,6 in this line kt stores only 0....

                Comment

                Working...