Feb 20, 2015 at 12:30pm UTC
Hi forum, i'm new here.
I'm creating a K value calculator. I'm wondering if i'm doing something
wrong because the value of K is ALMOST always like 1 or 0, even though it shouldn't.
Here is the source code:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float firstX;
float firstY;
float secondX;
float secondY;
float kphase1;
float kphase2;
float K;
cout << "Enter the first coordinate pair!" << endl;
cout << " " << endl;
cout << "Enter the first X's value: ";
cin >> firstX;
cout << "Enter the first Y's value: ";
cin >> firstY;
cout << " " << endl;
cout << "Enter the second X's value: ";
cin >> secondX;
cout << "Enter the second Y's value: ";
cin >> secondY;
cout << " " << endl;
cout << "The coordinate pairs are the following" << endl;
cout << " " << endl;
cout << "1th coordinate pair: (" << firstX << "," << firstY << ")" << endl;
cout << "2th coordinate pair: (" << secondX << "," << secondY << ")" << endl;
cout << " " << endl;
cout << "I will now calculate the value of K using this simple form: " << secondY << " - " << firstY << " / " << secondX << " - " << firstX << endl;
cout << " " << endl;
kphase1 = secondY - secondY;
kphase2 = secondX - firstX;
K = kphase1 / kphase2;
cout << "The value of K is: " << K << endl;
}
Sorry if my code is rather sloppy, i'm still a novice. I would appreciate any solution.
Last edited on Feb 20, 2015 at 12:36pm UTC
Feb 20, 2015 at 1:15pm UTC
Consider this: kphase1 = secondY - secondY ;
What might be the result of this?
Is it possible that you mean firstY
?
Feb 21, 2015 at 2:24am UTC
YOU ARE ABSOLUTELY RIGHT. God damnit... i'm so stupid.. hahaha.
It was supposed to be kphase1 = secondY - firstY;
As the formula for calculating the value of K is
secondY - FirstY / secondX - firstX :)
THANK YOU!
Last edited on Feb 21, 2015 at 2:28am UTC