2016-11-14 103 views
0

嗨,我是很新的编码但我有一个相当复杂的pshysics问题CPP解决,我已经遇到了一些问题使用函数作为另一个函数的输入

#include <stdio.h> 
#include <cmath> 
#include <iostream> 

using namespace std; 

double delta_x(double x, double n) 
{ 
    return x/n; 
} 

double theta(delta_x(double x,double n),double i, double a) 
{ 
    return atan(abs(2*a*((delta_x(x,n)*i)-50)-(0.01))); 
} 

Codeblox Givex的我以下错误:

|9|error: expected primary-expression before 'double'| 
|9|error: expected primary-expression before 'double'| 
|9|error: expected primary-expression before 'double'| 
|9|error: expected primary-expression before 'double'| 
|9|error: expression list treated as compound expression in initializer [-fpermissive]| 
|10|error: expected ',' or ';' before '{' token| 
|20|error: 'theta' cannot be used as a function| 

在此先感谢

+0

您不必再次传递'delta_x'。只需简单地说:'双重theta(双我,双a)'。它应该工作。 – iammilind

+0

在尝试解决复杂问题之前阅读一本好书“C++ Primer 5th edition” - 使用函数是您应该知道的基础知识的一部分 –

+0

我不会这样做,但它是我的phsycics练习的一部分,我需要为星期四sooo我不认为我有足够的时间在这一点上读取任何东西 – TheRlee

回答

1

没有必要通过delta_xtheta

double delta_x(double x, double n) 
{ 
    return x/n; 
} 

double theta(double i, double a) 
{ 
    return atan(abs(2*a*((delta_x(i,a)*i)-50)-(0.01))); 
} 
+0

实际上是一个'delta_x'参数我需要'x'和'n',它在'int main()'后面初始化 – TheRlee

+0

@TheRlee:写一个最小在你的问题中代表你的用例的例子 –

+0

所以我需要这部分程序来读取一些'n'值,为'n'计算'delta_x',然后用'delta_x'计算'和'i' – TheRlee

相关问题