Can't figure out this problem

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
Consider this: kphase1 = secondY - secondY;
What might be the result of this?
Is it possible that you mean firstY?
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
Topic archived. No new replies allowed.