一个程序,它有一个名为polar_to_rect()的函数,它将极坐标向量转换为矩形向量? [英] A program that has a function called polar_to_rect() that converts a polar vector to a rectangular vector?
本文介绍了一个程序,它有一个名为polar_to_rect()的函数,它将极坐标向量转换为矩形向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,我不知道如何修复错误,在最后一行说mag不能用作函数。如果有更多错误,请帮助我
我尝试过:
OKay, I'm dont know how to fix the error where it says "mag cannot be used as a function" in the last line. AND if there are more errors please help me
What I have tried:
#include<iostream>
#include<cmath>
using namespace std;
void polar_to_rect(double&, double&, double , double );
int main()
{
char ch;
double mag, angle, x, y;
cout<<" This program converts a polar vector to a rectangular vector.."<<endl<<endl;
while (ch != 'n')
{
cout<<"Enter the value of mag: ";
cin>>mag;
cout<<"Enter the value of angle: ";
cin>>angle;
polar_to_rect(mag,angle, x, y);
cout<<" >>x = "<<x<<endl;
cout<<" >>y= "<<y<<endl<<endl;
cout<<"Another calculation? (y/n)... ";
cin>>ch;
}
return 0;
}
void polar_to_rec(double _mag, double angle, double &x, double &y)
{
x = _mag(cos(angle));
y = _mag(sin(angle));
return;
}
推荐答案
C ++
不接受标准数学表达式(省略乘法运算符)你必须使用有效的C ++
表达式
C++
doesn't accept standard mathematical expressions (where the multiplication operator is omitted) you have to use validC++
expressions
Quote:
x = _mag(cos(angle));
y = _mag(sin(angle));
x = _mag(cos(angle));
y = _mag(sin(angle));
应该是
should be
x = _mag * cos(angle);
y = _mag * sin(angle);
这篇关于一个程序,它有一个名为polar_to_rect()的函数,它将极坐标向量转换为矩形向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文