Thread: adding vectors

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    22

    Question adding vectors

    Hi. I have written a bit of code to sum the components of vectors F=ai+bj+ck and compiled the code with Devc++4. The compiler keeps giving me parse error at the end of input. It's not the first time I've seen this, but I can't remember how to fix it. Thanks a bunch...
    Code:
    #include<iostream.h>
    #include<math.h>
    #include <stdlib.h>
    
    const int size=100;
    
    int main(){
    double F,theta,phi;
    double f1[size],theta1[size],phi1[size];
    double fx[size],fy[size],fz[size];
    double ratio,fxs,fys,fzs; int n,i;
    ratio=3.14159/180;
    
    cout<<"type in the number of vectors that you want to add up"<<endl;
    cin>>n;
    if(n<=size&&(n>1))
    {for(i=0;i<n;i++)
    {cout<<"type in f1, theta1 and phi1 for all vectors"<<endl;
    cin>>f1[i]>>theta1[i]>>phi1[i];
    cout<<"f1[i]="<<f1[i]<<" theta1[i]="<<theta1[i]<<" phi1[i]="<<phi1[i]<<endl;
    
    fx[i]=f1[i]*sin(theta1[i]*ratio)*cos(phi1[i]*ratio);
    fy[i]=f1[i]*sin(theta1[i]*ratio)*sin(phi1[i]*ratio);
    fz[i]=f1[i]*cos(theta1[i]*ratio);
    fxs=fxs+fx[i];
    fys=fys+fy[i];
    fzs=fzs+fz[i];}
    
    //Calculate F, theta and phi
    double fxy;
    F=sqrt(fxs*fxs+fys*fys+fzs*fzs);
    fxy=sqrt(fxs*fxs+fys*fys);
    if(F==0.0)
    {cout<<"magnitude of F is zero"<<endl;}
    return(1);
    
    theta=acos(fzs/F)/ratio;
    if(fxs<0.0)
    {phi=90.0;
    if(fys<0.0)
    {phi=-90.0;}}
    else
    {phi=atan(fys/(fxs*ratio));
    if(fxs<0.0)
    {phi=phi+180;}}
    cout<<"sumof vectors"<<endl;
    cout<<"F="<<F<<" theta="<<theta<<" phi="<<phi<<endl;
    system("PAUSE");
    return 0;}

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    your missing a closing bracket for your very first if statement..

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    22

    Thumbs up

    Thanks, that did it. Now I will look through the program next time I get that error.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 08:21 AM
  2. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  3. Adding Vectors
    By Tonto in forum Game Programming
    Replies: 5
    Last Post: 11-20-2006, 01:06 AM
  4. Adding vectors ??
    By Hussain Hani in forum C++ Programming
    Replies: 1
    Last Post: 11-18-2006, 03:03 AM
  5. SVN Import Causes Crash
    By Tonto in forum Tech Board
    Replies: 6
    Last Post: 11-01-2006, 03:44 PM