求模运算符%是取余数的意思
重点::求模运算符只用于整数,不能用于浮点
计算有英石与磅数
#include<iostream>
using namespace std;
//一英石等于14磅
int main(void)
{
int t_stones; //total stone
int t_baskets=14; //Every basket of stones
cout<<"Enter your weight in stones";
cin>>t_stones;
int stones=t_stones/t_baskets; //whole stone
int pounds=t_stones%t_baskets; //remainder in pounds
cout<<t_stones<<" pounds are"<<stones<<" stone "<<pounds<<" pounds";
}
重点::求模运算符只用于整数,不能用于浮点