- UID
- 14408
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-11-5
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
不好意思,我是个超级菜鸟,别见笑。我为学习arx,先学vc++,为学vc++,先学c++,我编了一个小计算器程序,编译通过,运行时输入y,总是不能继续,请各位大侠给看看。
不胜感激!
(compiler:vc++6.0;op:win2000)
代码如下:
#include <iostream.h>
#include <ctype.h>
void main()
{
int result;
int ContinueWorking();
do{
int badOperator=0;
cout<<"Pick an operator:+,-,*,/\n";
char operation;
cin>>operation;
int firstNumber,secondNumber;
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:
cout<<"You entered a bad operator."<<endl;
badOperator=1;
break;
}//switch
if(badOperator==0)
cout<<"The result is " <<result<<"."<<endl;
}while(ContinueWorking());
}
int ContinueWorking()
//ContinueWorking return 1 if the user presses'y'in response
//to our prompt ,and 0 if the user presses 'n' otherwise
{
//ContinueWorking
char response;
cout<< "Would you like to do another problem?(Y/N):";
do{
cin>>response;
response=tolower(response);
if(response!='y'&& response!='n'){
cout<< "Enter only 'Y'or'N':";
}
}while (response!='Y'&&response!='n');
return (response=='y') ? 1:0;
}//ContinueWorking |
|