#include "pch.h"
#include <iostream>
int main()
{
using namespace std;
const int foot = 12;
int hight;
cout << "Enter your hight(inches):___ ";
cin >> hight;
cout << "Your hight is " << hight / foot << " foot and " << hight % foot << " inches. " << endl;
return 0;
}
练习二:
#include "pch.h"
#include <iostream>
int main()
{
using namespace std;
//cout.setf(ios_base::fixed, ios_base::floatfield);
const int foot = 12;
const float meter = 0.0254;
const float pound = 2.2;
//要求用户输入身高信息(分别输入英尺英寸)
int foots;
cout << "*********BMI(Body Mass Index) Caculator*********" << endl;
cout << "Please enter your height (foot and inches):\nFoots is: ";
cin >> foots;
int inches;
cout << "Inches is: ";
cin >> inches;
cout << "All right!Your height is " << foots*foot+inches<<" inch." << endl;
//输入用户体重信息(英镑)
int pounds;
cout << "Enter your weight: ";
cin >> pounds;
cout << "Your weight is " << pounds << " pound.\n";
//转换各种单位
int total_inch = foots * foot + inches;
float height_meter = total_inch*meter;
float weight_kg = pounds / pound;
//输出BMI值
cout << "Your BMI is " << weight_kg / height_meter << " !\n";
return 0;
}
练习三:
#include "pch.h"
#include <iostream>
int main()
{
using namespace std;
const int hour = 60;
const int second = 60;
cout << "Enter a latitude in degrees, minutes, and seconds:\n";
int degrees;
cout << "First, enter the degrees: ";
cin >> degrees;
int minutes;
cout << "Next, enter the minutes of arc: ";
cin >> minutes;
int seconds;
cout << "Finally, enter the seconds of arc: ";
cin >> seconds;
cout << degrees << " degrees, " << minutes << " minutes, " << seconds << " seconds = ";
cout << degrees + minutes / double(hour) + second / double(second) / double(hour);
return 0;
}
练习四:
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
const int minute = 60;
const int hour = 3600;
const int day = 86400;
long seconds = 0;
cout << "Enter the number of seconds: ";
cin >> seconds;
cout << seconds << " seconds = " << seconds / day << " days, "
<< seconds % day / hour << " hours, "
<< seconds % hour / minute << " minutes, "
<< seconds % minute << " seconds." << endl;
return 0;
}
练习五:
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
long long world_popu = 0;
cout << "Enter the world's population: ";
cin >> world_popu;
long long us_popu = 0;
cout << "Enter the population of the US: ";
cin >> us_popu;
cout << "The population of the US is " << us_popu*100.0 / world_popu
<< "% of the world population.";
return 0;
}
练习六:
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
float miles = 0;
cout << "Enter the miles of your car driveing: ";
cin >> miles;
float gallon = 0;
cout << "Enter the gallon of the oil: ";
cin >> gallon;
cout << "Your car ride " << miles / gallon
<< " miles in 1 gallons.";
return 0;
}
练习七:
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
cout << "*******EU STYLE*******\n";
float kilemeter = 0;
cout << "Enter the distance(km) your car ride: ";
cin >> kilemeter;
float litres = 0;
cout << "Enter the litres of the oil: ";
cin >> litres;
cout << "Your car using " << litres / kilemeter*100.0
<< " L oil in 100km.\n";
cout << "*******USA STYLE*******\n";
float miles = 0;
float gallon = 0;
miles = 0.6214*kilemeter;
gallon = litres / 3.875;
cout << "Your car ride " << miles / gallon << " miles in 1 gallon." << endl;
return 0;
}