C++ C++;涉及数字的代码

C++ C++;涉及数字的代码,c++,math,cout,cin,pow,C++,Math,Cout,Cin,Pow,我需要这个代码的帮助。 代码的目的是将第一个数字乘以第二个数字,第二个数字乘以第三个数字(乘幂) 像这样的1*2^3 我有一个工作代码,但它没有给我结果 #include <iostream> #include <math.h> using namespace std; int main() { int a, b, c, d; // Request three numbers from the user cout << "Pleas

我需要这个代码的帮助。 代码的目的是将第一个数字乘以第二个数字,第二个数字乘以第三个数字(乘幂)

像这样的1*2^3

我有一个工作代码,但它没有给我结果

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int a, b, c, d;

    // Request three numbers from the user
    cout << "Please provide three numbers\n";
    cout << "First Number: ";
    cin >> a;
    cout << "Second Number: ";
    cin >> b;
    cout << "Third Number: ";
    cin >> c;

    // Multiply the numbers and display the result
    d = a * b^c; pow(b, c);

    cout << "\n" << a << " * " << b << " ^ " << c << "=" << d << "\n\n";
    return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
INTA、b、c、d;
//向用户请求三个数字
库塔;
cout>b;
cout>c;
//将数字相乘并显示结果
d=a*b^c;功率(b,c);

cout
^
不是幂运算符。您只需
a*pow(b,c)
您的算术不正确,您正在使用位运算符(^)处理与幂无关的内容

改用:

// Multiply the numbers and display the result
d = a * pow(b, c);
所以

a=2 b=3 c=2

你能行

2*3^2-->2*9=18

使用PoW(B,C)代替C++中的B^ C,^用于XOR二进制运算。如果你真的想使用^符号,可以对一些操作符进行重载,在后台调用POW,但将抽象为^,但这是附加代码。

< P>代码:

d=a*b^c;

不正确。^运算符是异或(请参阅)。应改用此运算符:

d = a * pow( b, c );

好运!

< p>替换<代码> d= a*b^ c;pOW(b,c);< /> > <代码> d= a*pWo(b,c);< /c> >,因为^运算符不表示C++中的幂。

<代码> b^ c不计算<代码> POW(b,c)< /代码>。