我弄了个计算机的程序,但是不知道哪出错了,希望能获得帮助,谢谢.
程序代码:// 计算器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;
int count = 0;
for( ; count < MAX; count++ )
Str2[count] = StrE[count];
for( ; *(StrE + index)!= '\0'; index2 ++ )
{
if( *(Str2 + index2) != ' ')
{
*(StrE + index) = *(Str2 + index2);
index++;
}
}
return;
}
double CarryO(char* StrE)
{
double value = 0;
int index = 0;
value = term( StrE,index );
for(;;)
{
switch( *(StrE + index++) )
{
case ' \0 ' :
return value;
case '+' :
value += term( StrE,index );
case '-' :
value -= term( StrE,index );
default :
cout << endl
<< "Warning!"
<< endl;
_getch();
exit(1);
}
}
}
double term(char* StrE,int& index)
{
double value = 0;
value = number(StrE,index);
while( (*(StrE +index) == '*') || (*(StrE + index) == '/'))
{
if(*(StrE + index) == '*')
{
index++;
value *= number(StrE,index);
}
if(*(StrE +index) == '/')
{
index++;
value /= number(StrE,index);
}
return value;
}
}
double number(char* StrE,int& index)
{
double value = 0.0;
while(isdigit(*(StrE + index) ) )
{
value = 10 * value + ( *(StrE + index++) - '0');
}
if(*(StrE + index) != '.')
return value;
double count = 1;
while((isdigit(*(StrE + index))))
{
count *= 0.1;
value = value + count * (*(StrE + index++) - '0');
return value;
}
}
运行出错








