求模運算符%是取餘數的意思
重點::求模運算符只用於整數,不能用於浮點
計算有英石與磅數
#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";
}
重點::求模運算符只用於整數,不能用於浮點