2016-07-15 3 views
-4

나는 이것에 대한 매우 간단한 대답이있을 것이라고 확신하지만, 몇 시간 동안 찾았고 그것을 이해할 수 없다. 제목에서 알 수 있듯이 코드에 주석을 달았습니다. 모든 것이 올바른 구문으로 보이기 때문에 그것이 무엇인지 모릅니다.오류 : 예상 ','또는 ';' before '{'token

#include <iostream> 
#include <math.h> 
using namespace std; 
float x, y, k, q, base, exponent; 

/*float atan(q) 
{ 
    //I had made my own functions for all the different math functions that 
    would have normally been included in the math.h file, but I had no idea 
    how to tackle making a function for an arc tangent as all the information 
    I could find online just had you kinda guess what the end result might be, 
    so I used the math.h file for this and only this function. 
}*/ 
float sqrot(k) 
{ // <----- the error is here 
    float guess, divide, average, z; 
    guess=rand()%k; 
    for(z;z<500;z++) 
    { 
     divide=k/guess; 
     average=(guess+divide)/2; 
     guess=average; 
    } 
} 
float cosine(y) 
{ 
    y=1-(((y*y)/2)+((y*y*y*y)/24)-((y*y*y*y*y*y)/720)); 
    return y; 
} 
float sine(x) 
{ 
    x=x-(((x*x*x)/6)+((x*x*x*x*x)/120)-((x*x*x*x*x*x*x)/5040)); 
    return x; 
} 
float power(base, exponent) 
{ 
    while(exponent>1) 
    { 
     base=base*base; 
     exponent-1; 
    } 
    return base; 
} 
float haversine(lat1,long1,lat2,long2) 
{ 
    float degree_to_rad, pi=3.14159; 
    int d_lat, d_long, a, c, mi; 
    degree_to_rad=pi/180; 
    d_lat=(lat2-lat1)*degree_to_rad; 
    d_long=(long2-long1)*degree_to_rad; 
    a=power(sine(d_lat/2),2)+cosine(lat*degree_to_rad)*cosine(lat2*degree_to_rad)*power(sine(d_long/2),2); 
    c=2*atan((sqrot(a))/(sqrot(1-a))); 
    mi=3956*c; 
    return mi; 
} 
int main() 
{ 
    int answer; 
    cout<<"Enter the Latitude of your starting location: "; 
    cin>>lat1; 
    cout<<"Enter the Longitude of your starting location: "; 
    cin>>long1; 
    cout<<"Enter the Latitude of your ending location: "; 
    cin>>lat2; 
    cout<<"Enter the Longitude of your ending location: "; 
    cin>>long2; 
    answer=haversine(lat1, long1, lat2, long2); 
    cout<<"The distance between the two points is: "<< answer; 
    return 0; 
} 
+1

다른 모든 기능

float sqrot(type k) // ^^^^ 

유사를 했어야 유형이 있어야합니다 시작을 위해 ... – John3136

+0

매개 변수의 유형을 지정해야합니다. 그렇지 않으면 컴파일러 "th 잉크 "기능 프로토 타입이며 세미 콜론이 필요합니다. –

+0

매개 변수에 대한 유형 지정자를 실제로 제공하는 것을 쉽게 수정할 수 있습니다. 그러나 당신은 더 이상 오류가 없을 것입니다 (http://coliru.stacked-crooked.com/a/cfdf9fa7a5aefb2b). –

답변

2

공식 인수

float sqrot(k) 

당신은 당신의 매개 변수 중 하나에 형태를 부여하지 않은

관련 문제