注意输出的格式(空格)。
#include<iostream>
using namespace std;
int main()
{
int limit;
cout << "Enter the speed limit:" << ' ';
cin >> limit;
int speed;
cout << "Enter the recorded speed of the car:" << ' ';
cin >> speed;
if (speed <= limit)
{
cout << "Congratulations, you are within the speed limit"
<< endl;
}
if (1 <= speed - limit&&speed - limit <= 20)
{
cout << "You are speeding and your fine is $ 100"
<< endl;
}
if (21 <= speed - limit&&speed - limit <= 30)
{
cout << "You are speeding and your fine is $ 270"
<< endl;
}
if (31 <= speed - limit)
{
cout << "You are speeding and your fine is $ 500"
<< endl;
}
return 0;
}