Herman09851
New Coder
Hi, I am a newbie to c++ and for college, I need to make a force calculator. I have done this so far but it won't calculate the Fx and Fy when I run it like this.
Does anybody know what I am doing wrong? ps. I need to use a void function in my code and I'm dutch that's why there are some lines in dutch in the code 🙂
Does anybody know what I am doing wrong? ps. I need to use a void function in my code and I'm dutch that's why there are some lines in dutch in the code 🙂
Code:
using namespace std;
double Force = 1.0, Angle, AmountF, Quadrant, Fx, Fy;
void checkkwadrant()
{
if (Quadrant == 2) {
//Quadrant 2 dus ten op zichte van xas in Quadrant 1 is een AmountF in Quadrant twee 180 - hoek weg van de x-as in Quadrant 1
Angle = 180 - Angle;
Force == -Force;
}
else if (Quadrant == 3) {
Angle = 180 + Angle;
Force == -Force;
}
else if (Quadrant == 4) {
Angle = 360 - Angle;
Force == -Force;
}
else if (Quadrant != 1 && Quadrant != 2 && Quadrant != 3 && Quadrant != 4)
{
//stap 5
cout << "Kwadrant " << Quadrant << " bestaat niet " << endl;
cout << "Vul een bestaande waarde in! ";
cout << "" << endl;
Fx = 0;
Fy = 0;
}
Fx = Force * cos(Angle);
Fy = Force * sin(Angle);
}
int main()
{
double Fx = 0.0, Fy = 0.0;
//stap 1:
cout << "Geef aantal krachten die berekend moeten worden: ";
//stap 2
cin >> AmountF;
cout << "" << endl;
//stap 3
cout << "Voer grootte in (zonder eenheid), hoek (in graden, vanaf x-as) en richting (welk Quadrant) in van elke vector." << endl;
for (int i = 0; i < AmountF; i++) {
//stap 4
cin >> Force;
cin >> Angle;
cin >> Quadrant;
//stap 6
//6a
Angle *= 3.14159 / 180;
//6b
checkkwadrant();
//6c
cout << "Fx = " << Fx << " en Fy = " << Fy << endl;
}
//Force = sqrt(Fx * Fx + Fy * Fy);
//Angle = atan2(Fy, Fx) * 180.0 / 3.14159;
cout << "Het resultant van de vector heeft een grootte: " << Force << " met een hoek van: " << Angle << " graden vanaf de x-as " << endl;
}