Speed < 10 display “Invalid speed”
10 <= Speed <= 120 display “Speed is within limit”
Speed > 120 display “Speed limit exceeded”
At the end the program should display a message “Thank you for using the program”.
Please find the code below with all comments and explaination also attached execution screenshot below
#include <bits/stdc++.h>
using namespace std;
int main()
{
//Initialising the const int maximum_speed_limit with 120 kmph and declaring the vaiable input_speed to read from user
const int maximum_speed_limit = 120;
int input_speed ;
//reading user speed into input_speed
cout << "Please enter the speed: \n" ;
cin >> input_speed ;
//checking the condition that input_speed is less than 10 or not if yes then we will output invalid speed
if(input_speed < 10)
{
cout << " Invalid speed \n" ;
}
//checking the condition that input_speed is greater than 10
else if (input_speed >= 10 )
{
//checking the condition that input_speed is less than maximum_speed_limit or not if yes then we will output speed is within limit
if (input_speed <= maximum_speed_limit)
{
cout << " Speed is within limit \n";
}
//else we will output speed limit exceeded
else
{
cout << " Speed limit exceeded \n";
}
}
//at the end we will output thank you for using the program
cout << " Thank you for using the program";
}
Screenshot 1 : speed < 10
screenshot 2: speed between 10 and 120 (both inclusively)
screenshot 3 : speed > 120
Get Answers For Free
Most questions answered within 1 hours.