I posted a challenge on a different BBS that asked for a program that checks to see if a set of 4 ordered pairs create a function on a graph or not (no x value is the same as another). I have created the program and it works fine, but I need to add one more thing to it. I need it to check to see if the ordered pairs are the same (in which if they were, they wouldn't stop it from creating a function). What I have so far is-
Code:
#include <iostream>
using namespace std;
int IsFunction(char OrderedPairs[20]);
int main()
{
char OrderedPairs[20];
int function;
cout << "Enter ordered pairs: ";
cin.getline(OrderedPairs, 20);
function = IsFunction(OrderedPairs);
if (function == 1)
cout << "Is not a function.";
else
cout << "Is a function.";
return 0;
}
int IsFunction(char OrderedPairs[20])
{
int a = OrderedPairs[1];
int b = OrderedPairs[6];
int c = OrderedPairs[11];
int d = OrderedPairs[16];
if (a == b || a == c || a == d)
return 1;
else if (b == c || b == d)
return 1;
else if (c == d)
return 1;
else
return 0;
}
I have thought of just doing like I did for the x values and assign them a letter of the alphabet and check it like that, but that seems a little unnessicary. What could I do to check to see if the ordered pairs were the same as another? Could I just assign the ordered pairs to different variables, remove the comma, and comapre them to each other?
Oh, and if you need to know, the program will be given ordered pairs like this-
Enter ordered pairs: (1,2)(3,4)(5,6)(7,8)
So I will not need to remove spaces. I will probley add some error checking when I get this part done.
The challenge is mine (I posted it for others to try) but I am just needing help with my own solution. I will not post any code y'all may supply for an example or a solution unless you give me permission, and even then you will get create for helping me out.
Thanks.