Advertisement
M_A_Tabarani

School Stuff 06

Oct 4th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. //Determine if the car meets the speed limit
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. const double MAXSP = 110;    //speed limit km/h, s=d/t
  7.  
  8. int main()
  9. {
  10.     double distance, time;
  11.     int vehicles;
  12.  
  13.     cout<<"Number of vehicles tested : ";
  14.     cin>>vehicles;
  15.  
  16.     int no=0;
  17.     while(no<vehicles)
  18.     {
  19.         cout<<"Enter distance taken by vehicle (in km) : ";
  20.         cin>>distance;
  21.  
  22.         cout<<"Enter times taken by vehicle (in minutes) : ";
  23.         cin>>time;
  24.  
  25.         double speed = distance / (time/60);
  26.         cout<<"The car moving with the speed "<<speed<<"km/h, which ";
  27.  
  28.         if(speed<=MAXSP)
  29.             cout<<"meets ";
  30.         else
  31.             cout<<"exceeds ";
  32.  
  33.         cout<<"the speed limit of"<<MAXSP<<"km/h."<<endl;
  34.         no=no+1;
  35.     }
  36.  
  37.     return 0;
  38. }
  39.  
  40.  
  41. //Using for loop
  42.  
  43. //Determine if the car meets the speed limit
  44.  
  45. #include <iostream>
  46. using namespace std;
  47.  
  48. const double MAXSP = 110;    //speed limit km/h, s=d/t
  49.  
  50. int main()
  51. {
  52.     double distance, time;
  53.     int vehicles;
  54.  
  55.     cout<<"Number of vehicles tested : ";
  56.     cin>>vehicles;
  57.  
  58.     for (int no=0;no<vehicles;no=no+1)
  59.     {
  60.         cout<<"Enter distance taken by vehicle (in km) : ";
  61.         cin>>distance;
  62.  
  63.         cout<<"Enter times taken by vehicle (in minutes) : ";
  64.         cin>>time;
  65.  
  66.         double speed = distance / (time/60);
  67.         cout<<"The car moving with the speed "<<speed<<"km/h, which ";
  68.  
  69.         if(speed<=MAXSP)
  70.             cout<<"meets ";
  71.         else
  72.             cout<<"exceeds ";
  73.  
  74.         cout<<"the speed limit of"<<MAXSP<<"km/h."<<endl;
  75.         no=no+1;
  76.     }
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement