Speed Limit Enforcer

Speed limit enforcer

Using only if statements for the logic; make a program that prompts the user to input their driving speed. If the speed is above 60, output "You're speeding! Slow down!". If it's below 30, output "You're driving too slow. It might be dangerous!".

If it's in between, output "You're driving within the safe speed limit.".

Answer

#include <iostream>

int main() {
	std::cout << "Input your driving speed.\n";
	float speed;
	std::cin >> speed;

	if (speed > 60)
	{
		std::cout << "You're speeding! Slow down!";
	}
	if (speed < 30)
	{
		std::cout << "You're driving too slow. It might be dangerous!";
	}
	if (speed <= 60 && speed >= 30)
	{
		std::cout << "You're driving within the safe speed limit.";
	}
}
Questions