# Program for a speed camera

I am doing some online exercises, and I came across this: "Your job is to write a program for a speed camera. For simplicity, ignore the details such as camera, sensors, etc and focus purely on the logic. Write a program that asks the user to enter the speed limit. Once set, the program asks for the speed of a car. If the user enters a value less than the speed limit, program should display Ok on the console. If the value is above the speed limit, the program should calculate the number of demerit points. For every 5km/hr above the speed limit, 1 demerit points should be incurred and displayed on the console. If the number of demerit points is above 12, the program should display License Suspended."

        Console.Write("Speed Limit :");
Console.WriteLine("SPEED LIMIT : " + speedLimit);
Console.WriteLine("***********************");

Console.Write("Car Speed : ");
Console.WriteLine("CAR SPEED : " + carSpeed);
Console.WriteLine("***********************");
Console.WriteLine("***********************");

int demeritPoints = 0;

if (carSpeed < speedLimit)
{
Console.WriteLine("Ok. You are good to go");
}
else
{
int speedDifference = carSpeed - speedLimit;

for (int counter = 5; counter <= speedDifference; counter += 1)
{
if (counter % 5 == 0)
{
demeritPoints++;
}
}
}
Console.Write("Demerit Points :");
Console.WriteLine(demeritPoints);

if (demeritPoints >= 12)
{
}
else
{
Console.WriteLine("You are not suspened");
}


• "You are not suspened" People don't get suspended. Licenses do. Might want to fix that, including the spelling.
– Mast
Oct 25, 2018 at 15:07

• Calculating the number of demerit points can be simplified to int demeritPoints = speedDifference / 5;.
• Instead of writing "SPEED LIMIT : " + speedLimit, you can use an interpolated string: \$"SPEED LIMIT: {speedLimit}", which makes formatting a little easier.