C++牛人帮忙~

来源:百度知道 编辑:UC知道 时间:2024/06/16 02:21:21
我编的一个算24点的程序,编译是无错,运行时总是退出,帮忙看看哪里有错
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

const double precision=1E-6;
const int the_number_of_cards=4; //牌的张数,便于修改
const int the_number_to_calculate=24; //计算的点数,便于修改
double number[the_number_of_cards]; //存储点数
string expression[the_number_of_cards]; //存储算式
string save[200]; //作为缓存区
bool Judgement=false; //判断是否有解
int count=0;

void calculate(int n)
{
int i,j,k;
if(n==1)
{
if(fabs(number[0]-the_number_to_calculate)<=precision)
{
save[k]=expression[0];
k++;
Judgement=true;
count++;
}
}

for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
double a,b;
string expression_a,expression_b;

a=number[i];
b=num

你的k没有初始化,在第十九行int i,j,k;后加上一句k=0;就行了。

我马上去学,等我学成之后吧,给你认真讲讲!

能当我老师吗?我QQ516714020 我初中想自学