C++求模(取餘)運算符與除法

求模運算符%是取餘數的意思

重點::求模運算符只用於整數,不能用於浮點

計算有英石與磅數

#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";		
}

重點::求模運算符只用於整數,不能用於浮點

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章