刚学c++的小白,求解
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
int a,b;
cin >>a>>b;
double d=(a-b)/b;
if((a-b)<=0)
{
cout <<"Not Speeding";
}
if((a-b)>0)
{
if(d>0 && d<=0.1)
{
cout << "Speeding Warning";
}
if(d>0.1 && d<=0.2)
{
cout << "Fine 100";
}
if(d>0.2 && d<=0.5 )
{
cout << "Fine 500";
}
if(d>0.5 && d<=1)
{
cout << "Fine 1000";
}
if(d>1)
{
cout << "Fine 2000";
}
}
return 0;
}
这篇博客讲解了一位初学者如何使用C++实现速度判罚逻辑,通过输入两个整数a和b,计算速度差并根据差值输出相应的警告或罚款等级。程序中包含了条件判断和多个if-else块来处理不同速度区间的情况。
902

被折叠的 条评论
为什么被折叠?



