#include<bits/stdc++.h>
#include<cstdlib>
using namespace std;
下面就是计算器的一些功能了(可以根据需要进行修改)。
while(n!='|'){
cin>>a>>n>>b;
//+ - * /
if(n=='+'){
cout<<a+b<<endl;
}
if(n=='-'){
cout<<a-b<<endl;
}
if(n=='*'){
cout<<a*b<<endl;
}
if(n=='/'){
if(b!=0){
cout<<a/b<<endl;
}else{
cout<<"错误"<<endl;
}
}
//~
if(n=='~'){
if(a<b){
int mu,ch;
ch=b;
srand(time(NULL));
mu=rand()%ch;
system("cls");
cout<<"0~"<<ch<<endl;
cout<<mu<<endl;
}else{
cout<<"错误"<<endl;
}
}
if(n=='!'){
system("cls");
char mn,nn;
int f,g;
cin>>f>>mn>>nn>>g;
if(mn=='!'){
if(nn=='='){
if(!(f==g)){
cout<<"是";
}else if(f==g){
cout<<"否";
}
}
if(nn=='<'){
if(!(f<g)){
cout<<"是";
}else if(f<g){
cout<<"否";
}
}
if(nn=='>'){
if(!(f>g)){
cout<<"是";
}else if(f>g){
cout<<"否";
}
}
}
}
}
(求余)
//%
if(n=='%'){
c=a;
d=b;
cout<<c/d<<endl;
}
(判断)
//> = <
if(n=='>'){
if(a>b){
cout<<"是"<<endl;
}else{
cout<<"否"<<endl;
}
}
if(n=='='){
if(a==b){
cout<<"是"<<endl;
}else{
cout<<"否"<<endl;
}
}
if(n=='<'){
if(a<b){
cout<<"是"<<endl;
}else{
cout<<"否"<<endl;
}
}
(求随机数)
//~
if(n=='~'){
if(a<b){
int mu,ch;
ch=b;
srand(time(NULL));
mu=rand()%ch;
system("cls");
cout<<"0~"<<ch<<endl;
cout<<mu<<endl;
}else{
cout<<"错误"<<endl;
}
}
1+1
2
1-1
0
1*1
1
1/1
1
1/0
错误
0~100
(略)
1>1
否
2>1
是
1<1
否
1<2
是
1=1
是
2=1
否