求助一个C++计算器

来源:百度知道 编辑:UC知道 时间:2024/06/17 14:36:29
请问如果用C++做一个能运算两个数之间的加减乘除的计算器怎么写啊?
列入输入:36+769
输出:805
两个数之间的加减乘除就行了
谢谢
一楼的朋友,运行了你的代码后,提示没有#include "stdafx.h"

程序如下,简单易行。

#include <stdlib.h>
#include <iostream>
using namespace std;

void main()
{
int n=1;
do
{
char signe,test[20]={"\0"},str1[10]={"\0"},str2[10]={"\0"};
int num1,num2,i=0,j=0,k=0;
cout<<"输入运算(如35+29): ";
cin>>test;

while(test[i])
{
str1[i++]=test[i];
if(test[i]=='+'||test[i]=='-'||test[i]=='*'||test[i]=='/')break;
}
signe = test[i++]; //取运算符号
while(test[i])
{
str2[j++]=test[i++];
}

num1 = atoi(str1);
num2 = atoi(str2);

if (signe=='+')cout<<num1<<" + "<<num2<<" = "<<num1+num2<<endl;
if (signe=='-')cout<<num1<<" - "<<num2<<" = "<<num1-num2<<