#include "iostream"
using namespace std;
const int inch_to_feet = 12;
int main()
{
cout << "输入你的身高(英寸):___\b\b\b";
int inch;
cin >> inch;
int feet = inch / inch_to_feet;
inch = inch % inch_to_feet;
cout << "你的身高为:" << feet << "英尺加上" << inch << "英寸" << endl;
return 0;
}
2,编写一个小程序,要求以几英尺几英寸的方式输入其身高,并以磅为单位输入其体重。(使用3个变量来存储这些信息。)该程序报告其BMI(Body Mass Index,体重指数)。为了计算BMI,该程序以英寸的方式指出用户的身高(1英尺为12英寸),并将以英寸为单位的身高转换为以米为单位的身高(1英寸=0.0254米)。然后,将以磅为单位的体重转换为以千克为单位的体重(1千克=2.2磅)。最后,计算相应的BMI——体重(千克)除以身高(米)的平方。用符号常量表示各种转换因子。
Enter a latitude in degrees, minutes, and seconds:
First, enter the degrees: 37
Next, enter the minutes of arc: 51
Finally, enter the seconds of arc: 19
37 degrees, 51 minutes, 19 seconds = 37.8553 degrees
#include "iostream"
using namespace std;
const int degree_to_minutes = 60;
const int minutes_to_seconds = 60;
int main()
{
cout << "Enter a latitude in degrees,minutes,and seconds:\n";
cout<<"First,enter the degrees:";
int degree;
cin>>degree;
cout<<"Next,enter the minutes of arc:";
int minute;
cin>>minute;
cout<<"Fianlly,enter the seconds of arc:";
int second;
cin>>second;
double show_in_degree;
show_in_degree=(double)degree+(double)minute/degree_to_minutes+(double)second/degree_to_minutes/minutes_to_seconds;
cout<<degree<<" degrees,"<<minute<<" minutes,"<<second<<" seconds = "<<show_in_degree<<" degrees\n";
return 0;
}
Enter the world's population: 6898758899
Enter the population of the US: 310783781
The population of the US is 4.50492% of the world population.
#include "iostream"
using namespace std;
int main()
{
cout << "Enter the world population:__\b\b";
long long world_population;
cin >> world_population;
cout << "Enter the population of the US:__\b\b";
long long US_population;
cin >> US_population;
double proportion;
proportion = (double)US_population / (double)world_population * 100;
cout << "The population of the US is "<<proportion <<"% of the world population."<<endl;
return 0;
}