c06.cpp

来自「此文件可以能帮你求体积」· C++ 代码 · 共 71 行

CPP
71
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?