⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c06.cpp

📁 《C++程序设计习题及解答》配套代码VC版
💻 CPP
字号:
// c06.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <iostream.h>
#include <ctype.h>

int continueWorking();

int main(int argc, char* argv[])
{
	int result;
	do 
	{
		cout <<"Key in an oprator: +, -, *, / ==> ";
		char operation;
		cin >> operation;
		int firstNumber, secondNumber;

		if ( operation != '+' 
			&& operation != '-'
			&& operation != '*'
			&& operation != '/' )
		{
			cout << "you entered a bad operator." << endl << endl;
			continue;
		}
		
		cout << "Enter your first number:";
		cin >> firstNumber;
		cout << "Enter your second number:";
		cin >> secondNumber;

		switch( operation )
		{
		case '+':
			result = firstNumber + secondNumber;
			break;
		case '-':
			result = firstNumber - secondNumber;
			break;
		case '*':
			result = firstNumber * secondNumber;
			break;
		case '/':
			result = firstNumber / secondNumber;
			break;
		default:
			break;
		}
		
		cout << "The result is " << result << "." << endl << endl;

	}while( continueWorking() );

	return 0;
}

int continueWorking()
{
	char response;
	do
	{
		cout << "continue?(y/n):(Enter only lower letter of 'y' or 'n')";
		cin >> response;
	}while( response != 'y' && response != 'n' );
	
	return ( response == 'y' );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -