C++ Primer Plus 第三章

//2

对于全局变量 const double pound = x,其中x的取值要是小数形式,在编译下分数不能转换成小数,结果出错。

问题:在vs2012编译环境下,浮点数的分数表示。

 

//4

#include <iostream>

using namespace std;


int main()
{
	long second = 0;
	int minute = 0;
	int hour = 0;
	int day = 0;
	int xsecond = 0;

	cout << "Enter the number of seconds:    \b\b\b";
	cin >> second;

	day = second / (24*60*60);
	hour = (second % (24*60*60)) / (60*60);
	minute = (second % (60*60)) / 60;
	xsecond = second % 60;

	cout << second << " seconds" << " = " << day << " days, " << hour << " hours, " << minute << " minutes, " <<  xsecond << " seconds."<<endl;

	system("pause");
	return 0;
	
}

//5

#include <iostream>

using namespace std;


int main()
{
	long long  world = 0;
	long long US = 0;
	double rate;
	cout << "Enter the world's population:    \b\b\b";
	cin >> world;
	cout << "Enter the  population of the US:    \b\b\b";
	cin >> US;
	rate = double (US)/(world);

	cout << "The population of the US is " << rate*100 << "%of the world population." << endl;

	system("pause");
	return 0;
	
}

注:rate = double (US)/(world); 要加double类型和括号。

 

//6

#include <iostream>

using namespace std;


int main()
{
	double mile = 0;
	double galoon = 0;
	double per_gal_mile = 0;

	cout << "Enter your miles:   \b\b";
	cin >> mile;
	cout << "Enter the galoon of the oil used:   \b\b";
	cin >> galoon;
	per_gal_mile = double (mile)/(galoon);

	cout << "When the oil used is one galoon,the car drive " << per_gal_mile << " miles." << endl;

	system("pause");
	return 0;
	
}


//7

尴尬题没读懂!!!我是一个假的汽车专业的学生。。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值