看到这篇文章的人可以给我和@快乐星空Maker点一个小小的赞吗?TT
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
void SetColorAndBackground(int ForgC, int BackC)
{
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
}
int main(){
double a,b;
char ch;
while(1){
double(a);
double(b);
cout<<"输入一个算式:\n";
cout<<"%是取余\n";
cout<<"$是开根(两个数)\n";
cout<<".也可以是乘\n";
SetColorAndBackground(14,0),
cin>>a>>ch>>b;
SetColorAndBackground(12,0);
switch(ch){
case '+':cout<<"\t答案是"<<a+b<<"!\n";break;
case '-':cout<<"\t答案是"<<a-b<<"!\n";break;
case '*':
case '.':
cout<<"\t答案是"<<a*b<<"!\n";break;
case '/':{
if(abs(b)<1e-9){
cout<<"除数不能为零!\n";
break;
}
cout<<"输入小数位数:";
int l;
cin>>l;
int ia=static_cast<int>(a);
int ib=static_cast<int>(b);
cout<<ia/ib<<'.';
int r=ia%ib;
for(int i=1;i<=l;i++){
cout<<(r*10)/ib;
r=(r*10)%ib;
}
cout<<endl;
break;
}
case '%': {
if(b==0){
cout<<"除数不能为零!\n";
break;
}
int ia=static_cast<int>(a);
int ib=static_cast<int>(b);
cout<<"\t答案是"<<ia%ib<<"!\n";
break;
}
case '$': {
if(a<0){
cout<<"不能对负数"<<a<<"开平方根!\n";
break;
}
if(b<0){
cout<<"不能对负数"<<b<<"开平方根!\n";
break;
}
cout<<"\t"<<a<<"答案是"<<sqrt(a)<<"!\n";
cout<<"\t"<<b<<"答案是"<<sqrt(b)<<"!\n";
break;
}
default:
cout<<"未知的运算符!\n";
break;
}
SetColorAndBackground(15,0);
system("pause");
system("cls");
}
return 0;
}