Trouble with using functions to transform 2 point form/ point-slope form to slope-intercept form

Thread Starter

Killerbee65

Joined May 15, 2017
256
Hello all!

So I am kinda having a brain fart moment here and forgot how to use functions, I wrote a code that uses functions to transform 2 point form/ point-slope form (based on user input) to slope-intercept form. I decided (for the sake of not wasting time) to continue on writing my code because I know the logic of what I need to do, just forgot how to call a function lol.

C++:
#include <iostream>
#include "diaze_lab5b.h"
using namespace std;

int   getProblem(int);// menu
void  get2Pt(float, float, float, float);//if user picked 1, enter two points
void  getPtslope(float, float, float);//if user picked 2, enter point and slope
float slopeintcptFrom2pt(float, float, float, float);//calculate y intercept
void  display(float, float, float, float);//displays two points
void  display(float, float, float);//displays one point and slope
float calc2Pt(float, float, float, float);//calculates slope for 2 point form
void  display(float, float);//displays slope intercept form for both options


int main(){

    if (getProblem(choice) == 1)
    {

        get2Pt(x, y, x1, y1);//two points entered
        display(x, y, x1, y1);//program displays equation 2 point equation
        calc2Pt();//calculation for slope is done
        slopeintcptFrom2pt(x, y, slope, yint);//calculation for y intercept
        display(slope, yint)//program displays final slope intercept form
}
    else if (getProblem(choice) == 2)
    {
        getPtslope(slope, x, y);//point and slope entered
        slopeintcptFrom2pt(x, y, slope, yint);//calulation for y intercept
        display(slope, x, y);//program displays point slope equation
        display(slope, yint)//program displays final slope intercept form
    }

int getProblem(int choice) {

        cout << "Select the form that you would like to convert to slope-intercept form :\n";
        cout << "1) Two   - point form(you know two points on the line)\n";
        cout << "2) Point - slope form(you know the line's slope and one point)\n";
        cin  >> choice;

    while (choice < 1 || choice > 2)
    {
        
        cout << "Error: the input must be 1, or 2\n";
        cin  >> choice;

    }

    return choice;
}


void get2Pt(float x, float y, float x1, float y1)
{

       cout << " now type in two points with a space seperating them (x y):";
       cin  >> x >> y;
       cout << "enter two more point, again seperated by a space (x y):";
       cin  >> x1 >> y1;

}
void getPtslope(float slope, float x, float y)
{
    cout << "now type in two points with a space seperating them (x y): ";
    cin  >> x >> y;
    cout << "Enter the slope of the line:";
    cin  >> slope;
}

float slopeintcptFrom2pt(float x, float y, float slope, float yint)
{
    float slopex = x * slope;
    yint = y - slopex;
    return yint;
}

void display(float x, float y, float x1, float y1)
{
    cout << "Two - point form\n";
    cout << "(" << y1 << "-" << y << ")\n";
    cout << "m = -------------------\n";
    cout << "(" << x1 << "-" << x << ")";
}

float calc2Pt(float x, float y, float x1, float y1)
{
    int yt = (y1 - y);
    int xt = (x1 - x);
    int slope = yt / xt;
    return slope;
}

void display(float slope, float x, float y)
{
    cout << "Point - slope form\n";
    cout << "y - " << y << "=" << slope << "(x - " << x << ")";
}

void display(float slope, float yint)
{
    cout << "Slope - intercept form\n";
    cout << "y = " << slope << "x -" << yint;
}
most (if not all) the errors that pop up are from undeclared variables. I completely forgot how to pass information from function to function using parameters. Also for some functions, I would need to return multiple inputs from the user and I would like to know how to go on about doing that using reference. One more thing, you'll notice 3 functions have the same name, I'm not sure if I did it right but from what I remember, if they have different parameters please let me know if this is correct. Also, I am sadly a visual learner so I apologize for all the questions lol :)
 

MrAl

Joined Jun 17, 2014
11,389
Hi,

Do you have a problem with the math behind this or just the programming aspect of it such as syntax?
 
Top