 |
Donate to remove ads, get special access and support the community!
-
Perkele
Join Date: Jul 2008
Location: Sandbox
Posts: 1,446
Rep: 630
Cash: 1,192
[Attempt] C++ Equation solver
YES I am a beginner.
So, I didn't even try to use any switches or cases in this program.
So it's plain if, cout, cin....
The important point in my program is that it works.
YES I know that this is as easy as C++ gets.
Code:
#include <iostream>
#include <windows.h>
#include <stdlib.h>
using namespace std;
double i;
double a;
double b;
double c;
double result1;
double result2;
double choise=1;
int main()
{
while (choise!=0)
{
system ("cls");
system ("color 0A");
SetConsoleTitle("Equation solver");
cout << "[Equation solver]\n";
cout << "ax+b=c\n\n";
cout << "[Values]\n";
cout << "a=";
cin >> a;
cout << "b=";
cin >> b;
cout << "c=";
cin >> c;
cout << "\n[Calculation]\n";
if (a==0)
{
cout << "Error #1! Don't set a as a zero (a!=0)!";
}
if (b>0 && a!=0 || b==0 && a!=0)
{
cout << a << "x+" << b << "=" << c << endl;
cout << a << "x=" << c << "-" << b << endl;
cout << a << "x=" << c-b << "|:" << a << endl;
cout << "x=" << (c-b)/a;
}
if (b<0 && a!=0)
{
cout << a << "x" << b << "=" << c << endl;
cout << a << "x=" << c << b << endl;
cout << a << "x=" << c-b << "|:" << a << endl;
cout << "x=" << (c-b)/a;
}
//Exit function//
cout << "\n\n[Continue]\nPress 1 to continue and 0 to exit: ";
cin >> choise;
}
}
This is how it works:
Code:
[Equation solver]
ax+b=c
[Values]
a=1
b=-2
c=3
[Calculation]
1x-2=3
1x=3+2
1x=5 |:1
x=5
[Continue]
Press 1 to continue and 0 to exit:
PS: I also have quadratic equation solver on my other computer,
just PM me if want it posted here (lazy on math, huh?).
Last edited by Xel; 12-14-2009 at 11:40 AM.
-
Private
Join Date: Aug 2007
Posts: 13
Rep: 13
Cash: 600
If you use else if statements you wont have to keep checking to make sure a!=0. It will make your code a lot more readable.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
 |
Bookmarks