-1

I'm extremely new with programming, and I mostly pieced this together straight out of textbooks, but I cannot get the damn thing to work. For some reason, my doubles (F1 for example) say that they haven't been declared. Here's the code.

// Vector Resultant Calculator by Jeffrey Weissman
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    double F1 = 0, double F2 = 0, double F3 = 0, double F4 = 0; // The initial forces
    double A1 = 0, double A2 = 0, double A3 = 0, double A4 = 0; // The initial angles
    double F1x = 0, double F2x = 0, double F3x = 0, double F4x = 0; // The calculated horizontal components
    double F1y = 0, double F2y = 0, double F3y = 0, double F4y = 0; // The calculated vertical components
    double Rx = 0, double Ry = 0, double R = 0, double RA = 0; // The calculated attributes of the Resultant Vector R
    string unit; // The unit of the force magnitudes

    std::cout << "Welcome to Jeffrey Weissman's Vector Resultant Calculator./n To begin, please enter the magnitude of the first vector. For now, please ignore all units.";
    std::cin >> F1; 
    std::cout << "Thank you. Please enter the angle, in degrees, of the vector. Please count the angle counterclockwise from the x axis.";
    std::cin >> A1;

    std::cout << "Thank you. Please enter the magnitude of the second vector.";
    std::cin >> F2;
    std::cout << "Thank you. Please enter the angle, in degrees, of the vector. Please count the angle counterclockwise from the x axis.";
    std::cin >> A2;

    std::cout << "Thank you. Please enter the magnitude of the third vector. If there is not a third vector, please enter 0";
    std::cin >> F3;
    std::cout << "Thank you. Please enter the angle, in degrees, of the vector. Please count the angle counterclockwise from the x axis. If there is not a third vector, please enter 0.";
    std::cin >> A3;

    std::cout << "Thank you. Please enter the magnitude of the fourth vector. If there is not a fourth vector, please enter 0";
    std::cin >> F4;
    std::cout << "Thank you. Please enter the angle, in degrees, of the vector. Please count the angle counterclockwise from the x axis. If there is not a fourth angle, please enter 0.";
    std::cin >> A4;

    std::cout << "Thank you. Now, please enter the unit of the force magnitudes.";
    std::cin >> unit;

    F1 * cos(A1) = F1x, F2 * cos(A2) = F2x, F3 * cos(A3) = F3x, F4 * cos(A4) = F4x;
    F1 * sin(A1) = F1y, F2 * sin(A2) = F2y, F3 * sin(A3) = F3y, F4 * sin(A4) = F4y;

    F1x + F2x + F3x + F4x = Rx;
    F1y + F2y + F3y + F4y = Ry;

    tan(Ry / Rx) = RA;
    Rx * Rx + Ry * Ry = R ^ 2;
    std::cout << "The Vector Resultant has magnitude " << R << " at an angle " << RA << " degrees from the x axis.";

}
  • 3
    You have many syntax errors. Please visit this page and find yourself a book: http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – bku_drytt Sep 21 '15 at 01:22
  • Thank you. That eliminated about 2/3 of my errors. But I'm having issues with the math stuff toward the end of the code. Any idea what's wrong with that? – theb3arjew Sep 21 '15 at 01:31
  • 2
    **Try something simpler.** The importance of this in programming cannot be overstated. Start with a program that is small and simple; when you have it working perfectly, add a little complexity. – Beta Sep 21 '15 at 01:36
  • I wish I could. But my Statics professor didn't teach us anything about programming and wants this done. – theb3arjew Sep 21 '15 at 01:38
  • Believe me, it's the fastest way to get it done. I'll take a look and see if I can help you, but after that I'll vote to close the question, because this is not the kind of help this site is designed for. – Beta Sep 21 '15 at 01:42
  • 1
    Understood. I actually think I managed to fix it myself. I borrowed some books from the library and I'm slowly but surely picking it up. Only thing left is to loop it, and that doesn't look too hard. Thank you so much for the help. – theb3arjew Sep 21 '15 at 01:53

2 Answers2

1

Here's a working solution. I am writing this in sympathy for students with an unreasonable professor, but this is not what we do on this site.

#include <iostream>
#include <math.h>

using std::cout;
using std::endl;
using std::cin;

int main()
{
  cout << "Welcome to Jeffrey Weissman's Vector Resultant Calculator" << endl;

  cout << "Please enter the magnitude (without units) and then the angle (in degrees, measured  counterclockwise from the x axis) of each vector. Omit all units. When you have entered all vectors, enter 0." << endl; 

  double mag=1.0, angle;
  double Sx=0.0, Sy = 0.0;

  cin >> mag;
  while(mag > 0.001)
  {
    cin >> angle;
    angle *= 3.14159/180.0;
    double x = cos(angle);
    double y = sin(angle);

    Sx += x;
    Sy += y;

    cin >> mag;
  }

  mag = sqrt(Sx*Sx + Sy*Sy);
  angle = atan2(Sy, Sx) * 180.0/3.14159;

  cout << "The Vector Resultant has magnitude " << mag << " at an angle " << angle << " degrees from the x axis." << endl;
  return 0;
}
Beta
  • 96,650
  • 16
  • 149
  • 150
0

Try something simpler (another approach).

If your existing program has error's, a self taught programming co-worker once taught me to

Divide and conquer.  

Simply disable the compile of those parts of the program with problems using #if(0) ... #endif.

He often simply split the code in half ... just to determine if his coding problem was in the 1st or second half.

Expand the disabled code until you get a clean compile.  

Now you have isolated problems to work on. (And perhaps generate a MCVE for creating a question for SO.)

Narrow the search

Your first efforts are to find where the errors begin ... not just in the sense of line numbers, but also in the sense of program logic.

Then get to work on the earliest error 1st.

2785528
  • 5,438
  • 2
  • 18
  • 20