"C2447: '{' : missing function header (old-style formal list?)"是什么意思?

What does "C2447: '{' : missing function header (old-style formal list?)" mean?

本文关键字:list 意思 formal 是什么 function C2447 missing header old-style      更新时间:2023-10-16

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

#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.datn");
    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
}

这是谐振子的四阶runger-kutta解,我从计算物理h . landau那里得到的,我不知道如何解决这个问题,请帮助我!

这一行(rk4 subroutine注释前一行):

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

不应该在末尾有分号,因为您正在定义函数。