第5题
#include<iostream>intmain(){usingnamespace std;
cout <<"Enter the world's population:";longlong pup;
cin >> pup;
cout <<"Enter the population of the US:";longlong US;
cin >> US;double rate =100.0* US / pup;
cout <<"The population of US is "<< rate <<"\% of the world population.";return0;}
第6题
#include<iostream>intmain(){usingnamespace std;
cout <<"Please choose the units:<A> US <B> CHN"<< endl;char ch;
cin >> ch;if(ch =='A'){
cout <<"Please input the total mileage(miles):_____\b\b\b\b\b";double miles;
cin >> miles;
cout <<"Please input the gas(gallons):_____\b\b\b\b\b";double gals;
cin >> gals;
cout <<"Ok, "<< miles / gals <<" miles per gallon.";}elseif(ch =='B'){
cout <<"Please input the total mileage(km):_____\b\b\b\b\b";double kilm;
cin >> kilm;
cout <<"Please input the gas(litre):_____\b\b\b\b\b";double litre;
cin >> litre;
cout <<"Ok, "<< litre /(kilm /100)<<" litres gas per 100km.";}else{
cout <<"Your input is wrong!"<< endl;}return0;}
第7题
#include<iostream>intmain(){usingnamespace std;
cout <<"Please input the total mileage(km):_____\b\b\b\b\b";double kilm;
cin >> kilm;double miles = kilm *(100/62.14);
cout <<"Please input the gas(litre):_____\b\b\b\b\b";double litre;
cin >> litre;double gallons = litre *(1/3.875);
cout <<"Ok, "<< miles / gallons <<" miles per gallons."<< endl;return0;}