2016-07-15 7 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) 

は、他のすべての機能

関連する問題