Math++
Posted: Tue Apr 28, 2009 10:10 pm
I was bored today and decided to write a small program to do my Algebra homework for me. This took no more then 10 minutes so its probably a little sloppy. :D
I wrote this for factoring trinomials.
Basically without this code if I had the formula "m2 - 7m - 30" I would have to find a set of factors of "-30" that added up to "-7".
If i wanted to solve the equation with this code "7" would be the first number (enter the middle number first) and -30 would be the second number (enter the last number second).
This would be the output of the equation "m2 - 7m - 30".
Thats basically all there is to it.
Code: Select all
#include <iostream>
using namespace std;
int main(void)
{
while(1){
int firstnumber = 0;
int secondnumber = 0;
int variable1 = 0;
int variable2 = 0;
cout << "Enter the first number: ";
cin >> firstnumber;
system("cls");
cout << "Enter the second number: ";
cin >> secondnumber;
system("cls");
while(variable1 + variable2 != firstnumber)
{
variable1++;
variable2 = secondnumber / variable1;
cout << " ( x = " << variable1 << " ) ( x = " << variable2 << " ) WRONG" << endl;
}
cout << endl << endl;
cout << endl << endl << " ( x = " << variable1 << " ) ( x = " << variable2 << " ) CORRECT" << endl << endl << endl;
system("pause");
system("cls");
}
return 0;
}
Basically without this code if I had the formula "m2 - 7m - 30" I would have to find a set of factors of "-30" that added up to "-7".
If i wanted to solve the equation with this code "7" would be the first number (enter the middle number first) and -30 would be the second number (enter the last number second).
This would be the output of the equation "m2 - 7m - 30".
Code: Select all
( x = 1 ) ( x = -30 ) WRONG
( x = 2 ) ( x = -15 ) WRONG
( x = 3 ) ( x = -10 ) WRONG
( x = 3 ) ( x = -10 ) CORRECT