进制转换器

oct→八进制
dec→十进制
hex→16进制

int main() {
	cout << "BHD Converter\n";
	cout << "1.Decimal to octal or hexadecimal\n";
	cout << "2.Octal to decimal or hexadecimal\n";
	cout << "3.Hexadecimal to octal or decimal\n";
	int choose{};
	int num{};
	cout << "select the conversion you need:";
	cin >> choose;
	switch (choose)
	{
	case 1:
		cout << "Enter a decimal number:";
		cin >> num;
		cout << oct;//修改cout显示整数的方式
		cout << "octal is " << num << endl;
		cout << hex;//同上
		cout << "hexadecimal is " << num;
		break;
	case 2:
		cout << "Enter a octal number:";
		cin >> oct;//修改输入整数的方式
		cin >> num;
		cout << "decimal is " << num << endl;
		cout << hex;
		cout << "hexadecimal is " << num;
		break;
	case 3:
		cout << "Enter a hexadecimal number:";
		cin >> hex;
		cin >> num;
		cout << oct;
		cout << "octal is " << num << endl;
		cout << dec;
		cout << "decimal is " << num;
		break;
	default:
		break;
	}
	system("pause");
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值