什么" C2447:' {' :缺少函数头(旧式正式列表?)"意思?

时间:2015-09-24 18:19:05

标签: c++

帮我解决这个错误!非常感谢你!

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <math.h>
#include<iostream>
using namespace std;
#define N 2 // number of equations
#define dist 0.1 //step size
#define MIN 0.0   //minimum x
#define MAX 10.0  //maximum x
int main() {
    double x, y[N];
    //int j;
    void runge4(double x, double y[], double step);         //header
    double f(double x, double y[], int i);
    FILE *output; // save data in rk4.dat
    output= fopen("rk4.dat","w"); 
    y[0]= 1.0;//initial position
    y[1]= 0.0;///initial velocity
    fprintf(output, "%f/t%f/n",x,y[0]); 
    for (x= MIN; x<= MAX; x+= dist) {
        runge4(x, y,dist);
        fprintf(output,"%f/t%f/n", x, y[0]); //position vs time
    }
    printf("data stored in rk4.dat\n");
    fclose(output); 
} //end of main program
void runge4(double x, double y[], double step); 
 {  //rk4 subroutine
   double f(double x, double y[], int i);
   double h = step/2.0
   t1[N],t2[N],t3[N],k1[N],k2[N],k3[N],k4[N];
   int i;
   for (i = 0; i<N; i++) t1[i]=y[i]+0.5*(k1[i]=step*f(x,y,i));
   for (i = 0; i<N; i++) t2[i]=y[i]+0.5*(k2[i]=step*f(x+h,t1,i));
   for (i = 0; i<N; i++) t3[i]=y[i]+(k3[i]=step*f(x+h,t2,i));
   for (i = 0; i<N; i++) k4[i]=step*f(x+step,t3,i);
   for (i = 0; i<N; i++) y[i]+=(k1[i]+2*k2[i]+2*k3[i]+k4[i])/6.0;
 }
double f(double x, double y[], int i) 
{ //RHS equations
if (i==0) return(y[1]);           //RHS of first equation
if (i==1) return(-y[0]);          //RHS of second equation
}

它是谐振子的4阶runger-kutta解决方案,我从计算物理学H.Landau得到了这个。我不知道如何解决这个问题,请帮助我!

1 个答案:

答案 0 :(得分:2)

这一行(rk4 subroutine评论之前的那一行):

void runge4(double x, double y[], double step); 

最后不应该有分号,因为你正在定义函数。