0

我知道以前有人问过这个问题,但那里的答案似乎与我遇到的问题无关。

这是我的代码

#include <iostream>

int main()
{
    double E;
    double R;
    double t;
    double C;
    
    std::cout << "This program will calculate the current flowing through an RC curcuit!\n\n";
    std::cout << "Please enter the power source voltage value in Volts: ";
    std::cin >> E;
    std::cout << "\n\n";
    std::cout << "Please enter the total resistance value in Ohms: ";
    std::cin >> R;
    std::cout << "\n\n";
    std::cout << "Please enter the time elapsed after the switch closed Seconds: ";
    std::cin >> t;
    std::cout << "\n\n";
    std::cout << "Please enter the total capacitance value in Farads: ";
    std::cin >> C;
    std::cout << "\n\n";
    double RC = R * C;
    double ER = E / R;
    double pow = -t / RC;
    double expo = 2.71828 ** pow; //this line is the problem...

    double I = ER * expo;
    std::cout << "The current flowing through this circuit is: " << I;

    return 0;
}

我真的不知道这意味着什么,尽管在谷歌上查找它......有人可以解释一下,一般来说,如何避免这种类型的错误,而不仅仅是解决这个特定的实例吗?

4

1 回答 1

2

C++ 没有**像某些语言那样的运算符。您需要使用该std::pow函数来做指数,或者std::exp用于将数学常数提高到幂的特定情况e

#include <cmath>

...

double expo = std::exp(pow);
于 2021-10-13T00:46:01.300 回答