C++에서 알 수없는 오류, 오류 : ';'앞에 예상 기본 표현식이 있습니다. 토큰.C++에서 알 수없는 오류, 오류 : ';'앞에 예상 기본 표현식이 있습니다. 토큰
#include <iostream>
#include <math.h>
#include <stdio.h>
#define G 6.674E-11
using namespace std;
int main()
{
//Ms = Mass of sun, Me = Mass of Earth, Fg = Gravitational force between them, As = Acceleration of Sun, Ae = Acceleration of Earth, Ve_x
// = initial velocity of Earth in x direction, Ve_y = initial velocity of Earth in y direction, Vs_x = initial velocity of the Sun in x direction
// Vs_y = initial velocity of sun in y direction, t = time, F = Gravitational force ` between the two bodies.
float Ms, Me, Fg, As, Ae, Ve_x, Ve_y, Vs_x, Vs_y, pos_E, pos_S, r_x, r_y, r, t;
float S_dist;
float E_dist;
float F;
float Ve[2];
float Vs[2];
float pe[2];
float ps[2];
FILE *fileptr;
cout <<"Enter mass of the Sun in kg\n";
cin >> Ms;
cout <<"Enter mass of the earth in kg\n";
cin >> Me;
cout <<"Enter intial velocity of the sun in x direction in m/s\n";
cin >> Vs[0];
cout <<"Enter intial velocity of the sun in y direction in m/s\n";
cin >> Vs[1];
cout <<"Enter intial velocity of the earth in x direction in m/s\n";
cin >> Ve[0];
cout <<"Enter intial velocity of the earth in y direction in m/s\n";
cin >> Ve[1];
cout <<"Enter intial position of the sun in x component\n";
cin >> ps[0];
cout <<"Enter intial position of the sun in y direction\n";
cin >> ps[1];
cout <<"Enter intial position of the earth in x direction\n";
cin >> pe[0];
cout <<"Enter intial position of the earth in y direction\n";
cin >> pe[1];
for (t=0; t<30000; t+1)
{
float E_dist;
float S_dist;
float F;
E_dist=sqrt(((pe[0]-pe[0])*(pe[0]-pe[0])) + ((pe[1]-pe[1])*(pe[1]-pe[1])));
S_dist=sqrt(((ps[0]-ps[0])*(ps[0]-ps[0])) + ((ps[1]-ps[1])*(ps[1]-ps[1])));
r_x=((pe[0]-pe[0]) - (ps[0]-ps[0]));
r_y=((pe[1]-pe[1]) - (ps[1]-ps[1]));
r= sqrt((r_x)*(r_x) + (r_y)*(r_y));
F=(G*Me*Ms)/(r*r);
Ae = F/Me;
As = F/Ms;
Ve_x = Ve[0];
Ve_y = Ve[1];
Vs_x = Vs[0];
Vs_y = Vs[1];
}
cout<<"At time "<<t<<":\n The position of the Sun is "<<S_dist<<"\n The position of the Earth is "<<E_dist
<<"\n The acceleration of the Sun is "<<As<<" \n The acceleration of the Earth is "<<Ae<<" \nThe velocity of the Sun in the x direction is "
<<Vs_x<<" \n The velocity of the Sun in the y direction is "<<Vs_y<<" \n The velocity of the Earth in the x direction is "<<Ve_x<<
" \n The velocity of the Earth in the y direction is "<<Ve_y<<" \n The gravitational force between the Sun and the Earth is "<<F<<; // ERROR OCCURRED HERE.
}
이 덕분에 어떤 도움을 보내 주시기 바랍니다 는 여기에 내가 C++로 작성한 코드입니다.
이것은 (루프에서) 잘못되었습니다. 't + 1'. 그것은't'의 값을 변화시키지 않습니다. 표현을 평가하고 결과를 버립니다. 무한 루프가 있습니다. 또한 ... 루프 인덱스 변수의 부동 소수점 숫자? –
이것은 Google에서 가장 많이 검색 한 문제 중 하나입니다 (700 만 개의 결과 만). 컴파일러 작성자가 무엇이 잘못되었는지를 알려줄 것이라고 생각할 것입니다. –
안녕하세요 @Pat. 스택 오버플로에 오신 것을 환영합니다. 오류를 찾을 수 있도록 프로그램을 게시 해 주셔서 감사합니다. 오류가없는 모든 행을 처음으로 삭제 한 경우 훨씬 더 작은 프로그램을 남겨두면 더 많은 도움이됩니다. 이 디버깅 기술에 대한 자세한 내용은 http://sscce.org를 참조하십시오. 다시 한 번 환영합니다! –