fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double displacement(double I, double F,double a)
  5. {
  6. double D = 0;
  7.  
  8. if(I <=0 || F <= 0)
  9. cout<<"\nVelocity should be greater than zero.";
  10.  
  11. if(a == 0)
  12. cout<<"\nNo brakes were applied";
  13.  
  14. if(a <0)
  15. cout<<"\nThe vehicle is speeding up";
  16.  
  17. if(F > I)
  18. cout<<"\nError in acceleration values.";
  19.  
  20. else
  21. D = (F*F -I*I)/(-2*a);
  22.  
  23. return D;
  24. }
  25. int main() {
  26.  
  27. double I,F,a;
  28.  
  29. cout<<"\nEnter initial velocity : ";
  30. cin>>I;
  31.  
  32. cout<<"\nEnter final velocity : ";
  33. cin>>F;
  34.  
  35. cout<<"\nEnter deceleration : ";
  36. cin>>a;
  37.  
  38. if(displacement(I,F,a) > 0)
  39. cout<<"\nDisplacement is "<<displacement(I,F,a);
  40.  
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0s 4396KB
stdin
1 2 0
stdout
Enter initial velocity : 
Enter final velocity : 
Enter deceleration : 
No brakes were applied
Error in acceleration values.