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
#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;
}
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".
Martyj wrote:Nice, can it handle quadratics where the leading coefficient isn't 1? Like 3x^2 + 6x + 24
This program isn't for solving the equation, just factoring out the trinomials. It wouldn't really matter if the first number had a coefficient anyways.
EDIT: My bad I misunderstood your question. Ive just learned about quadratics today and no it doesnt handle them. Im probably going to make another program for quadratics because I have homework for it. :D
I made a console program to do my physics homework (horizontal projectiles launched at an angle). I don't think there's anything wrong with doing it this way, because I actually learned a lot by getting the program to generate the correct output.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Back in the old days, we programmed our fancy calculators in BASIC or asm to do our homework for us. That and play bubble bobble. This might be ill-advised though, not that playing/programming games in class is a bad thing, it's just that whenever I do trigonometry now I get the uncontrollable urge to bust out my NES
MarauderIIC wrote:I'll go ahead and move this over to code snippets
Thank you.
dandymcgee wrote:I made a console program to do my physics homework (horizontal projectiles launched at an angle). I don't think there's anything wrong with doing it this way, because I actually learned a lot by getting the program to generate the correct output.
Yea it actually makes homework semi-fun and builds problem solving skills as well as coding knowledge. I use C++ to solve my science conversion problems as well. :D
MarauderIIC wrote:Be aware when doing this sort of thing that, well, to put it simply, floats are weird and can easily not do what you'd expect them to.
Yeah.. I found out the hard way that when you mix ints and floats in equations you get rather strange results if you don't cast first.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!