Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Determine if the car meets the speed limit
- #include <iostream>
- using namespace std;
- const double MAXSP = 110; //speed limit km/h, s=d/t
- int main()
- {
- double distance, time;
- int vehicles;
- cout<<"Number of vehicles tested : ";
- cin>>vehicles;
- int no=0;
- while(no<vehicles)
- {
- cout<<"Enter distance taken by vehicle (in km) : ";
- cin>>distance;
- cout<<"Enter times taken by vehicle (in minutes) : ";
- cin>>time;
- double speed = distance / (time/60);
- cout<<"The car moving with the speed "<<speed<<"km/h, which ";
- if(speed<=MAXSP)
- cout<<"meets ";
- else
- cout<<"exceeds ";
- cout<<"the speed limit of"<<MAXSP<<"km/h."<<endl;
- no=no+1;
- }
- return 0;
- }
- //Using for loop
- //Determine if the car meets the speed limit
- #include <iostream>
- using namespace std;
- const double MAXSP = 110; //speed limit km/h, s=d/t
- int main()
- {
- double distance, time;
- int vehicles;
- cout<<"Number of vehicles tested : ";
- cin>>vehicles;
- for (int no=0;no<vehicles;no=no+1)
- {
- cout<<"Enter distance taken by vehicle (in km) : ";
- cin>>distance;
- cout<<"Enter times taken by vehicle (in minutes) : ";
- cin>>time;
- double speed = distance / (time/60);
- cout<<"The car moving with the speed "<<speed<<"km/h, which ";
- if(speed<=MAXSP)
- cout<<"meets ";
- else
- cout<<"exceeds ";
- cout<<"the speed limit of"<<MAXSP<<"km/h."<<endl;
- no=no+1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement