问题标题: 简单计算器(不喜勿喷)

0
0
已解决
李奕歌
李奕歌
初级天翼
初级天翼
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
double a,c;
char b;
int jia(){
	system("color 01");
    cout<<"="<<a+c;
}
int jian(){
	system("color 02");
    cout<<"="<<a-c;
}
int cheng(){
	system("color 03");
    cout<<"="<<a*c;
}
int chu(){
	system("color 04");
	cout<<"=";
    printf("%.2f",a/c);
}
int cifang(){
	system("color 05");
    cout<<"="<<pow(a,c);
}
int main(){
	while(1){
	system("color 07");
	cout<<"计算器:\n";
	cin>>a>>b>>c;
	if(b=='+') jia();
	if(b=='-') jian();
	if(b=='*') cheng();
	if(b=='/') chu();
	if(b=='^') cifang();
	Sleep(1000);
	system("cls");
	system("color 06");
	cout<<"\t\t\t是否继续?按Y继续,按N退出";
	char c=getch();
	if(c=='N' || c=='n') break;	
	if(c=='Y' ||c=='y') system("cls");
	}
	return 0;
}

 

李奕歌在2021-02-22 17:21:23追加了内容
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
double a,c;
char b;
int jia(){
	system("color 01");
    cout<<"="<<a+c;
}
int jian(){
	system("color 02");
    cout<<"="<<a-c;
}
int cheng(){
	system("color 03");
    cout<<"="<<a*c;
}
int chu(){
	if(c==0) cout<<"错误!";
	else{
	system("color 04");
	cout<<"=";
    printf("%.2f",a/c);	
	}
}
int cifang(){
	if(a!=0 || c!=0){
	system("color 05");
    cout<<"="<<pow(a,c);	
	}
	else cout<<"错误!"; 
}
int main(){
	while(true){
	system("color 07");
	cout<<"计算器:\n";
	cin>>a>>b>>c;
	if(b=='+') jia();
	if(b=='-') jian();
	if(b=='*') cheng();
	if(b=='/') chu();
	if(b=='^') cifang();
	Sleep(1000);
	system("cls");
	system("color 06");
	cout<<"\t\t\t是否继续?按Y继续,按N退出";
	char c=getch();
	if(c=='N' || c=='n') break;	
	if(c=='Y' ||c=='y') system("cls");
	}
	return 0;
}

 


1
已采纳
沙宸安
沙宸安
中级启示者
中级启示者

建议引入 除以0 和 0的0次方 两个判断机制,防止程序运行错误。

2
汪恺恒
汪恺恒
中级启示者
中级启示者

不错,但最好判断,如果除数为0,提示输入错误

0
0
0
0
刘英杰
刘英杰
新手天翼
新手天翼

建议:添加更高级算法(需要更高级知识)

如:分数次方、方程(组)求解、分式方程(组)求解、不等式(组)求解、多次根式化简、整式化简、分式化简、因式分解、无理数演算求值、求导、配方、积分、微分、少数定理证明过程演示、部分猜想叙述、单一加密解码字符序列等

虽然很艰难,却总得有人做(滑稽)

0
蔡乐毅
蔡乐毅
高级光能
高级光能

直接用计算机也比这个好

来个高精度吧,毕竟电脑里几e几e的好烦

0
孙楷航
孙楷航
资深光能
资深光能

在电脑里的计算器不香吗

0
0
黄硕梁
黄硕梁
初级天翼
初级天翼

在电脑里的计算器不香吗

0
黄子澄
黄子澄
中级天翼
中级天翼

直接用计算器不想吗?

0
李奕歌
李奕歌
初级天翼
初级天翼

@朱小川 小川,你敢吗

0
我要回答