Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Quadratic Solver

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming -> Binaries
View previous topic :: View next topic  
Author Message
talkerzero
Grandmaster Cheater
Reputation: 1

Joined: 24 Jul 2008
Posts: 560
Location: California

PostPosted: Tue Apr 14, 2009 1:30 pm    Post subject: Quadratic Solver Reply with quote

This will solve the any quadratic equation using the quadratic formula given the values of A, B, and C.
Code:
#include <stdio.h>

int main()
{
   int a          = 0;
   int b          = 0;
   int c          = 0;
   int discriminant    = 0;
   int bottom       = 0;
   int top[2]       = {0, 0};
   int solution[2]    = {0, 0};

   for(;;)
   {
      printf("Enter the values of a, b, and c: ");
      scanf("%i %i %i", a, b, c);

      discriminant = (b ^ 2) - (4 * a * c);
      top[0] = (b - (2 * b)) + (discriminant  ^ (1/2));
      top[1] = (b - (2 * b)) - (discriminant ^ (1/2));
      solution[0] = top[0] / 2 * a;
      solution[1] = top[1] / 2 * a;

      if(discriminant < 0)
         printf("\tThe solution is undefined.\n\n");
      else if(discriminant == 0)
         printf("\tThe solution is %i.\n\n", solution[0]);
      else if(discriminant > 0)
         printf("\tThe solutions are %i and %i.\n\n", solution[0], solution[1]);;
   }
   
   return EXIT_SUCCESS;
}


Any advice?
Back to top
View user's profile Send private message Visit poster's website
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Wed Apr 15, 2009 2:14 pm    Post subject: Re: Quadratic Solver Reply with quote

talker0 wrote:
Code:
      discriminant = (b ^ 2) - (4 * a * c);
      top[0] = (b - (2 * b)) + (discriminant  ^ (1/2));
      top[1] = (b - (2 * b)) - (discriminant ^ (1/2));
Any advice?
You're xor'ing there. Also remember the parentheses:
talker0 wrote:
Code:
      solution[0] = top[0] / 2 * a;
      solution[1] = top[1] / 2 * a;


talker0 wrote:
Code:
      if(discriminant < 0)
         printf("\tThe solution is undefined.\n\n");
It isn't... :)
Back to top
View user's profile Send private message
VolatileAce
Cheater
Reputation: 0

Joined: 19 Mar 2009
Posts: 30
Location: 0001001100110111

PostPosted: Wed Apr 15, 2009 3:44 pm    Post subject: Reply with quote

Code:
/**
 * @author VolatileAce
 */

#include "stdafx.h"
#include <iostream>
#include <math.h>

using namespace std;

void main(){
   double a, b, c;
   cout << "Enter a, b and c seperated by space inbetween: ";
   cin >> a >> b >> c;
   if(!a){
      cout << "The solution is undefined. (Reason: a = 0)" << endl;
      exit(0);
   }
   c = b*b-4*a*c;
   b = -b;
   a *= 2;
   if(c < 0){
      cout << "The solution is not a real number. (Reason: b*b-4*a*c is negative)" << endl;
      exit(0);
   }
   c = sqrt(c);
   b = (b - c) / a;
   c = c / a + b;
   if(c == b)
      cout << "The solution is " << b << "." << endl;
   else
      cout << "The solutions are " << c << " and " << b << "." << endl;
}
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Apr 15, 2009 4:13 pm    Post subject: Reply with quote

void main(), really?
Back to top
View user's profile Send private message
hacksign23
Master Cheater
Reputation: 0

Joined: 26 Nov 2006
Posts: 404

PostPosted: Thu Apr 16, 2009 12:19 am    Post subject: Reply with quote

hmm isn't this just like -b +/- sq((b*b) - 4ac) = bla,/2c,,yes?
_________________
Back to top
View user's profile Send private message AIM Address
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Thu Apr 16, 2009 8:21 am    Post subject: Reply with quote

No. It's:


_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
92Garfield
I'm a spammer
Reputation: 57

Joined: 20 Dec 2007
Posts: 5871
Location: Banana Republic Germany

PostPosted: Sun May 10, 2009 2:27 am    Post subject: Reply with quote

lol

ax² + bx + c = 0

That part is clear right?

and this is formular



p = b/a
q = c/a

why dont you just use cin/cout, i cant get this running

Jani wrote:
It isn't... Smile

if basic quantity are the real numbers then the solution set is empty

with complex numbers its just

sqrt(discrminant*-1)*i

just so noone can say I diddnt define i
i² = -1
i = sqrt(-1)

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming -> Binaries All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites