请教个问题,多谢
// 计算器00.cpp : 定义控制台应用程序的入口点。//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <cctype>
#include <cstdlib>
using std::cin;
using std::cout;
using std::endl;
void eatspace( char* StrE ) ;
double CarryO( char* StrE );
double term( char* StrE,int& index );
double number( char* StrE,int& index );
int _tmain(int argc, _TCHAR* argv[])
{
const int MAX = 20;
char Str1[MAX] = {0};
double reasult = 0;
for(;;)
{
cin.getline(Str1,MAX);
eatspace(Str1);
if( !Str1[0] )
return 0;
reasult = CarryO(Str1);
cout << "Reasult = " << reasult;
}
_getch();
return 0;
}
void eatspace( char* StrE )
{
const int MAX = 20;
char Str2[MAX] = {0};
int index = 0;
int index2 = 0;
for( ; StrE[index] != '\0'; index ++ )
if( *(StrE + index) != ' ')
{
*(Str2 + index2) = *(StrE + index);
index2++;
}
return;
}
double CarryO(char* StrC)
{
double value = 0;
int index = 0;
value = term( StrC,index );
for(;;)
{
switch( *(StrC + index++) )
{
case '+' :
value += term( StrC,index );
case '-' :
value -= term( StrC,index );
case ' \0 ' :
return value;
default :
cout << endl
<< "Warning!"
<< endl;
exit(1);
}
}
}
double term(char* StrT,int& index)
{
double value = 0;
value = number(StrT,index);
if( *(StrT + index) != '\0')
{if(*(StrT + index) == '*')
{
value *= number(StrT,index);
return value;
}
if(*(StrT +index) == '/')
{
value /= number(StrT,index);
return value;
}
}
return value;
}
double number(char* StrT,int& index)
{
double value = 0.0;
while(isdigit(*(StrT + index) ) )
{
value = 10 * value + ( *(StrT + index++) - '0');
}
if(*(StrT + index) != '.')
return value;
double count = 1;
while((isdigit(*(StrT + index))))
{
count *= 0.1;
value = value + count * (*(StrT + index++) - '0');
return value;
}
}