Jump to content

OK seriously need DIRECT HELP

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
russian777

russian777

    Newbie

  • Members
  • PipPip
  • 29 posts
So i been trying to debug this and yet i am still getting a 0.00000 value , so if anyone can jus alter this code and post it back up as an entire programme it would be helpfull.

#include <stdio.h>

#include <stdlib.h>

#include<math.h>

#define pi 3.1416

#define brkFactor 0.7

int main()

{

    double slopeRad,slopeTan,roadSlope,skidLength,speedCar;

    char carModel[200];

    

  

        printf("Enter the name of the car model\n");

                      scanf("%s",carModel);

        printf("Enter the skid length\n");

                      scanf("%d",&skidLength);           

        printf("Enter the roadSlope\n");

                      scanf("%d",&roadSlope);

                      

        slopeRad = roadSlope*(pi/180);

        slopeTan= sin(slopeRad)/ cos(slopeRad);

        speedCar = sqrt(30*skidLength*(slopeTan+brkFactor);

        

        printf("the slope rad is %f\n",slopeRad);

        printf("the slope tan is %f\n",slopeTan);

        printf("The %s has a speed of %d ;\n",carModel,speedCar);

        

    system("pause");

    return 0;

}


#2
birinight

birinight

    Learning Programmer

  • Members
  • PipPipPip
  • 36 posts
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define pi 3.1416
#define brkFactor 0.7
int main()
{
    double slopeRad,slopeTan,roadSlope,skidLength,speedCar;
    char carModel[200];
    
  
        printf("Enter the name of the car model\n");
                      scanf("%s",carModel);
        printf("Enter the skid length\n");
                      scanf("%lf",&skidLength);           
        printf("Enter the roadSlope\n");
                      scanf("%lf",&roadSlope);
                      
        slopeRad = roadSlope*(pi/180);
        slopeTan= sin(slopeRad)/ cos(slopeRad);
        speedCar = slopeRad+slopeTan;
        
        printf("the slope rad is %lf\n",slopeRad);
        printf("the slope tan is %lf\n",slopeTan);
        printf("The %s has a speed of %lf ;\n",carModel,speedCar);
        

    return 0;
}

You are using %d to doubles. %d is a decimal.
For floats use %f and for doubles use %lf