Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › quadratic equations C++ style...
New Posts  All Forums:Forum Nav:

quadratic equations C++ style...

post #1 of 2
Thread Starter 
I just spent a while writing a program that does quadratic equations. it gives you the solutions, and shows you the steps needed to get those solutions. the only thing you have to do is input a, b and c. this is great for checking your homework answers and showing where you went wrong. not much of a point to useing it to do the hw completely for you though because with most teachers you have to show work and all that. anyway, heres the source code:

#include <iostream>
#include <iomanip>
#include <cstring>
#include <windows.h>
#include <cmath>

using namespace std;

int main(){
cout << " WELCOME * QUADRAQUATION * WELCOME" << endl << endl;
int probnum, loopnum = 1;
cout << "Input Total Number of Equations: ";
cin >> probnum;

while (loopnum <= probnum){
float a = 0, b = 0, c = 0, x1 = 0, sqr1 = 0, sqr2 = 0, sqr3 = 0;
float sqrf = 0, neg = 0, pos = 0, div1 = 0, div2 = 0;

cout << "Input a, b and c Separated by Spaces: ";
cin >> a >> b >> c;

x1 = b/-1;

//STEP 1- SQR
sqr1 = b*b;
cout << "x=" << x1 << "+ [sqrt]" << sqr1 << "-4ac[/sqrt]" << endl;

//STEP 2- SQR
sqr2 = -4*a*c;
cout << "x="<<x1<<"+ [sqrt] "<< sqr1 << "+" <<sqr2 << "[/sqrt]" << endl;

//STEP3- SQR
sqr3 = sqr1 + sqr2;
cout << "x=" << x1 << "+ [sqrt]" << sqr3 << "[/sqrt]" << endl;

//STEP 4 (FINAL)- SQR
sqrf = sqrt(sqr3);
cout << "x=" << x1 << "+" << sqrf << endl;

//POSITIVE WORK
pos = x1 + sqrf;
cout << endl << "Positive Work:" << endl;
cout << "x="<<x1<<"+" << sqrf << endl;
cout << "x="<< pos << endl;
pos = pos / (2*a);
cout << "x=" << pos << endl<< endl;

//NEGATIVE WORK
neg = x1 - sqrf;
cout << "Negative Work:" << endl;
cout << "x="<<x1<<"+" << sqrf << endl;
cout << "x="<< neg << endl;
neg = neg / (2*a);
cout << "x=" << neg << endl <<endl;

Beep(500,500);
cout << "S = {" << neg << ", " << pos << "}" << endl;

loopnum = loopnum + 1;
system("Pause");
system("cls");
cout << " WELCOME * QUADRAQUATION * WELCOME" << endl << endl;
}

}

any suggestions??
My System
(13 items)
 
  
CPUMotherboardOS
p4 3.0GHz intel ummm i'll chek l8er windows xp home 
  hide details  
Reply
My System
(13 items)
 
  
CPUMotherboardOS
p4 3.0GHz intel ummm i'll chek l8er windows xp home 
  hide details  
Reply
post #2 of 2
If it works, very nice!

Did you need suggestions b/c it wasn't working or something to make it better?

If nothing, then good job. That could help some people out who need to know if their answer is right.
2nd Personal PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 2.4ghz abit IP35 Pro 8800GTS 512mb 8gb G.Skill DDR2 800 
Hard DriveOSMonitorKeyboard
2x150gb Raptor X's Vista x64 24" Samsung LCD Logitech Elite Keyboard 
PowerCaseMouseMouse Pad
700W OCZ GameXStream Thermaltake Armor Logitech G9 Laser Func Pad 
  hide details  
Reply
2nd Personal PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 2.4ghz abit IP35 Pro 8800GTS 512mb 8gb G.Skill DDR2 800 
Hard DriveOSMonitorKeyboard
2x150gb Raptor X's Vista x64 24" Samsung LCD Logitech Elite Keyboard 
PowerCaseMouseMouse Pad
700W OCZ GameXStream Thermaltake Armor Logitech G9 Laser Func Pad 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › quadratic equations C++ style...