Note that there are some explanatory texts on larger screens.

plurals
  1. POUnknown error on C++, error: expected primary expression before ';' token
    text
    copied!<p>Unknown error on C++, error: expected primary expression before ';' token. Here is the code I wrote in C++:</p> <pre><code> #include &lt;iostream&gt; #include &lt;math.h&gt; #include &lt;stdio.h&gt; #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 &lt;&lt;"Enter mass of the Sun in kg\n"; cin &gt;&gt; Ms; cout &lt;&lt;"Enter mass of the earth in kg\n"; cin &gt;&gt; Me; cout &lt;&lt;"Enter intial velocity of the sun in x direction in m/s\n"; cin &gt;&gt; Vs[0]; cout &lt;&lt;"Enter intial velocity of the sun in y direction in m/s\n"; cin &gt;&gt; Vs[1]; cout &lt;&lt;"Enter intial velocity of the earth in x direction in m/s\n"; cin &gt;&gt; Ve[0]; cout &lt;&lt;"Enter intial velocity of the earth in y direction in m/s\n"; cin &gt;&gt; Ve[1]; cout &lt;&lt;"Enter intial position of the sun in x component\n"; cin &gt;&gt; ps[0]; cout &lt;&lt;"Enter intial position of the sun in y direction\n"; cin &gt;&gt; ps[1]; cout &lt;&lt;"Enter intial position of the earth in x direction\n"; cin &gt;&gt; pe[0]; cout &lt;&lt;"Enter intial position of the earth in y direction\n"; cin &gt;&gt; pe[1]; for (t=0; t&lt;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&lt;&lt;"At time "&lt;&lt;t&lt;&lt;":\n The position of the Sun is "&lt;&lt;S_dist&lt;&lt;"\n The position of the Earth is "&lt;&lt;E_dist &lt;&lt;"\n The acceleration of the Sun is "&lt;&lt;As&lt;&lt;" \n The acceleration of the Earth is "&lt;&lt;Ae&lt;&lt;" \nThe velocity of the Sun in the x direction is " &lt;&lt;Vs_x&lt;&lt;" \n The velocity of the Sun in the y direction is "&lt;&lt;Vs_y&lt;&lt;" \n The velocity of the Earth in the x direction is "&lt;&lt;Ve_x&lt;&lt; " \n The velocity of the Earth in the y direction is "&lt;&lt;Ve_y&lt;&lt;" \n The gravitational force between the Sun and the Earth is "&lt;&lt;F&lt;&lt;; // ERROR OCCURRED HERE. } </code></pre> <p>Would be grateful for any help, thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload