📄 c06.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 + -