Created
May 11, 2018 16:48
-
-
Save edenizk/71a9da9afa56ee885491322ca6067b59 to your computer and use it in GitHub Desktop.
QUADRATIC EQUATIONS CALCULATOR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <math.h> | |
| #include <iostream> | |
| #include <windows.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <conio.h> | |
| #include <time.h> | |
| using namespace std; | |
| /* run this program using the console pauser or add your own getch, system("pause") or input loop */ | |
| void progressbar(){ | |
| cout<<"\t\t\t\t "; | |
| /*Loading bar*/ | |
| for(int i=0; i<100/5; i++){ | |
| cout<<(char)177; | |
| } | |
| cout<<"<<\r\t\t\t\t"; | |
| for(int i = 0; i<=100; i++){ | |
| cout << "\r\t\t " << i << "% completed >>" ; | |
| for (int o=1;o<i/5;o++){ | |
| cout<<(char)219; | |
| } | |
| switch (i% 4) | |
| { | |
| case 0: cout<<"\r\t\t/"; break; | |
| case 1: cout<<"\r\t\t-"; break; | |
| case 2: cout<<"\r\t\t\\"; break; | |
| case 3: cout<<"\r\t\t-"; break; | |
| } | |
| Sleep(50); | |
| } | |
| cout<<endl; | |
| } | |
| int main(int argc, char** argv) { | |
| float x,a,b,c,d,d2; | |
| char again; | |
| do{ | |
| cout<<"\t ~WELCOME TO THE QUADRATIC EQUATIONS CALCULATOR~\n"; | |
| cout<<"\t -a(if you dont have a value type '0'): "; | |
| cin>>a; | |
| //tester | |
| if(cin.fail()){ | |
| cin.clear(); | |
| cin.ignore(10, '\n'); | |
| cout<<"\t -Its Not a number\n\t -Please write it again\n"; | |
| cout<<"\t -Please write a positive or negative value(it must be a number):"; | |
| cin>>a; | |
| if(cin.fail()){ | |
| cout<<"\n\n\n\t -Please next time try to write a number..."; | |
| break; | |
| } | |
| } | |
| //tester | |
| cout<<"\t -b(if you dont have a value type '0'): "; | |
| cin>>b; | |
| //tester | |
| if(cin.fail()){ | |
| cin.clear(); | |
| cin.ignore(10, '\n'); | |
| cout<<"\t -Its Not a number\n\t -Please write it again\n"; | |
| cout<<"\t -Please write a positive or negative value(it must be a number):"; | |
| cin>>b; | |
| if(cin.fail()){ | |
| cout<<"\n\n\n\t -Please next time try to write a number..."; | |
| break; | |
| } | |
| } | |
| //tester | |
| cout<<"\t -c(if you dont have a value type '0'): "; | |
| cin>>c; | |
| //tester | |
| if(cin.fail()){ | |
| cin.clear(); | |
| cin.ignore(10, '\n'); | |
| cout<<"\t -Its Not a number\n\t -Please write it again\n"; | |
| cout<<"\t -Please write a positive or negative value(it must be a number):"; | |
| cin>>c; | |
| if(cin.fail()){ | |
| cout<<"\n\n\n\t -Please next time try to write a number..."; | |
| break; | |
| } | |
| } | |
| //tester | |
| if (a==0){ | |
| if (b==0){ | |
| if(c==0){ | |
| cout<<"\t\t- all values are 0\n\t\t- please write any value "; | |
| } | |
| else | |
| cout<<"\t\t- b and a are 0\n\t\t- no answer "; | |
| } | |
| else | |
| cout<<"\t\t- a is 0\n\t\t- x = "<<-c/b; | |
| } | |
| else { | |
| cout<<"\t -we are creating your discriminant please wait. :) \n"; | |
| progressbar(); | |
| d=(b*b-4*a*c); | |
| if (d<0){ | |
| cout<<"\t-discriminant is smaller then 0\n\t\t- no result "; | |
| } | |
| else if(d>0){ | |
| cout<<"\t\t-discriminant is bigger then 0\n\t\t- x = "<<(-b+sqrt(d))/(2*a)<<endl<<"\t\t- x2 = "<<(-b-sqrt(d))/(2*a); | |
| } | |
| else if(d==0) | |
| cout<<"\t\t-discriminant is equal to 0\n\t\t- x = "<<-b/(2*a); | |
| } | |
| cout<<"\n\t\t ~Do you wanna continue?[Y/N]~"; | |
| cin>>again; | |
| }while(again=='y'||again=='Y'); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment