Math++

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Bludklok
Chaos Rift Junior
Chaos Rift Junior
Posts: 241
Joined: Tue Apr 14, 2009 1:31 am
Current Project: EnigmaCore
Favorite Gaming Platforms: PC, N64, Playstation1, Playstation2
Programming Language of Choice: C++
Location: New Jersey
Contact:

Math++

Post by Bludklok »

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

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;
}
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".

Code: Select all

  
  ( x = 1 )   ( x = -30 )               WRONG
  ( x = 2 )   ( x = -15 )               WRONG
  ( x = 3 )   ( x = -10 )               WRONG


  ( x = 3 )   ( x = -10 )               CORRECT
Thats basically all there is to it.
Youtube
Website
Current project: Enigma Core
Martyj
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Thu Apr 23, 2009 11:23 am
Location: Ogden Utah
Contact:

Re: Math++

Post by Martyj »

Nice, can it handle quadratics where the leading coefficient isn't 1? Like 3x^2 + 6x + 24
User avatar
Bludklok
Chaos Rift Junior
Chaos Rift Junior
Posts: 241
Joined: Tue Apr 14, 2009 1:31 am
Current Project: EnigmaCore
Favorite Gaming Platforms: PC, N64, Playstation1, Playstation2
Programming Language of Choice: C++
Location: New Jersey
Contact:

Re: Math++

Post by Bludklok »

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
Youtube
Website
Current project: Enigma Core
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Math++

Post by dandymcgee »

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. :mrgreen:
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Math++

Post by MarauderIIC »

I'll go ahead and move this over to code snippets :)
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Altus
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 5
Joined: Mon Apr 27, 2009 3:35 am
Location: Seattle, WA

Re: Math++

Post by Altus »

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 :shock:
User avatar
Bludklok
Chaos Rift Junior
Chaos Rift Junior
Posts: 241
Joined: Tue Apr 14, 2009 1:31 am
Current Project: EnigmaCore
Favorite Gaming Platforms: PC, N64, Playstation1, Playstation2
Programming Language of Choice: C++
Location: New Jersey
Contact:

Re: Math++

Post by Bludklok »

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. :mrgreen:
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
Youtube
Website
Current project: Enigma Core
austech
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 8
Joined: Fri Oct 31, 2008 10:53 pm

Re: Math++

Post by austech »

Hmm, this makes me want to make programs to do my geometry homework :P

But it is true that it makes studying a little fun and learn. Maby now I wont fail my math tests :lol:
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Math++

Post by MarauderIIC »

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.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Math++

Post by dandymcgee »

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! :twisted:
Post Reply