gpt4 book ai didi

c++ - if 语句运行时错误

转载 作者:搜寻专家 更新时间:2023-10-31 02:17:34 24 4
gpt4 key购买 nike

我最初有 3 个方程式:Pu、Pm 和 Pd。它运行良好。在我引入 if 语句(根据循环迭代对 3 个方程进行变体)后,我收到运行时错误。任何帮助将不胜感激。

提前干杯。

#include <cmath>
#include <iostream>
#include <vector>
#include <iomanip>


int Rounding(double x)
{
int Integer = (int)x;
double Decimal = x - Integer;

if (Decimal > 0.49)
{
return (Integer + 1);
}
else
{
return Integer;
}
}

int main()
{
double a = 0.1;
double sigma = 0.01;
int delta_t = 1;
double M = -a * delta_t;
double V = sigma * sigma * delta_t;
double delta_r = sqrt(3 * V);
int count;

double PuValue;
double PmValue;
double PdValue;

int j_max;
int j_min;

j_max = Rounding(-0.184 / M);
j_min = -j_max;

std::vector<std::vector<double>> Pu((20), std::vector<double>(20));
std::vector<std::vector<double>> Pm((20), std::vector<double>(20));
std::vector<std::vector<double>> Pd((20), std::vector<double>(20));

std::cout << std::setprecision(10);
for (int i = 0; i <= 2; i++)
{
count = 0;
for (int j = i; j >= -i; j--)
{
count = count + 1;
if (j = j_max) // Exhibit 1C
{
PuValue = 7.0/6.0 + (j * j * M * M + 3 * j * M)/2.0;
PmValue = -1.0/3.0 - j * j * M * M - 2 * j * M;
PdValue = 1.0/6.0 + (j * j * M * M + j * M)/2.0;
}
else if (j = j_min) // Exhibit 1B
{
PuValue = 1.0/6.0 + (j * j * M * M - j * M)/2.0;
PmValue = -1.0/3.0 - j * j * M * M + 2 * j * M;
PdValue = 7.0/6.0 + (j * j * M * M - 3 * j * M)/2.0;
}
else
{
PuValue = 1.0/6.0 + (j * j * M * M + j * M)/2.0;
PmValue = 2.0/3.0 - j * j * M * M;
PdValue = 1.0/6.0 + (j * j * M * M - j * M)/2.0;
}
Pu[count][i] = PuValue;
Pm[count][i] = PmValue;
Pd[count][i] = PdValue;

std::cout << Pu[count][i] << ", ";
}
std::cout << std::endl;
}
return 0;
}

最佳答案

您正在分配而不是检查是否相等:j_max 到您的 if 语句中的 j

if (j = j_max)
// ^

else if (j = j_min)
// ^


if (j = j_max) 更改为 if (j == j_max),
else if (j = j_min)else if (j == j_min)

关于c++ - if 语句运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35617970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com