And this is what I have so far: [ made a mess of it and now im lost] Please feel
ID: 3771803 • Letter: A
Question
And this is what I have so far: [made a mess of it and now im lost] Please feel free to change or modify whatever seems fit, as long as it's clean and abides by the above directions, thanks:
#include<iostream>
#include<cmath>
using namespace std;
double negativeSquare(double &a,double &b,double &c);
double quadCalculator(double &a, double &b, double &c);
int menu(double &x, double &y, double &z);
int menu(double &x, double &y, double &z)
{
int m;
int coef;
bool menuflag = 1;
bool cin_flag = 1;
do
{
cout << " *-_-*-_-*| Guten Tag! |*-_-*-_-*-__ " << endl;
//cout << "How may I help you today: " << endl;
cout << endl;
cout << "To Give Me Your Coefficients Press:" << " < 1 >" << endl;
cout << "To Calculate Solutions Press:" << " < 2 >" << endl;
cout << "To Get Rid Of This Weird Black Box Press:" << " < 3 >" << endl;
cin.clear();
cin >> m;
cout << endl;
if (m == 1)
{
return 1;
}
else if (m == 2)
{
if (cin_flag == 0)
{
return 1;
}
cout << endl;
cout << endl;
cout << endl;
cout << "Not so fast, gimme some coefficients first " << endl;
cout << endl;
cout << endl;
cout << endl;
return 1;
}
else if (m == 3)
{
return 3;
}
else if (m == 1 || m == 2 || m == 3)
{
menuflag = 0;
}
} while (menuflag == 1);
return m;
}
int main()
{
double a, b, c;
double answerOne;
double answerTwo;
double x, y, z;
int m;
int coef;
m = menu(x,y,z);
bool cin_flag = 0;
bool menuflag = 0;
if (m == 3)
{
cout << "Auf Wiedersehen!" << endl;
return 0;
}
do {
cout << "*-_-*-___|Hello and Welcome to the Almighty Quadratic Solver|__-*-_-*" << endl;
cout << "*_-*-_-*-_-*-__|Don't panic we are here to Solve the Day|__-*-_-*-_-*" << endl;
cout << " ****************|HOWEVER|***************" << endl;
cout << " We require only two things from you: " << endl;
cout << endl;
cout << " First, don't feed me a Zero coefficient as an input for A." << endl;
cout << endl;
cout << " Second, we just met, so how about we take it slow and start" << endl;
cout << " off with only numbers and nothing else, oh and by numbers I mean" << endl;
cout << " three coefficients ;-)." << endl;
cout << endl;
cout << endl;
if (m==2)
{
cout << "Ahem, so let's begin." << endl;
cout << "Please give me your first coefficient: " << endl;
cin >> a;
if (a == 0)
{
cout << endl;
cout << endl;
cout << " Oh C'mon!" << endl;
cout << " What am I a schmuck on wheels!" << endl;
cout << " I'm outta here." << endl;
cout << endl;
cout << endl;
cout << endl;
return 0;
}
if (a == cin.fail())
{
cout << "ERROR: must be a valid number and non-zero." << endl << endl;
cin.clear();
cin.ignore();
return 0;
}
cout << endl;
cout << "Now, your second: " << endl;
cin >> b;
if (b == cin.fail())
{
cout << "ERROR: must be a valid number and non-zero." << endl << endl;
cin.clear();
cin.ignore();
return 0;
}
cout << endl;
cout << "And lastly, your third: " << endl;
cin >> c;
if (c == cin.fail())
{
cout << "ERROR: must be a valid number and non-zero." << endl << endl;
cin.clear();
cin.ignore();
return 0;
}
}
int check;
check = (pow((b*b) - (4 * a*c), 0.5));
if (check<0)
{
cout << endl;
cout << endl;
cout << endl;
cout << " [Uh Oh]" << endl;
cout << " We have been informed that the numbas you gave us " << endl;
cout << " were inappropriate, thus, we cannot 'Solve the Day'." << endl;
cout << " Yippee ki-yay!" << endl;
cout << endl;
cout << endl;
cout << endl;
return 0;
}
} while (m == 1);
//double quadCalculator(double a, double b, double c,double answerOne,double answerTwo);
answerOne=((-b + ((pow((b*b) + (4 * a*c), 0.5)))) / (2 * a));
answerTwo=((-b - ((pow((b*b) + (4 * a*c), 0.5)))) / (2 * a));
cout << endl;
cout << endl;
cout << "Okay" << endl;
cout<< "So here's what we got: " << answerOne << " & " << answerTwo << endl;
cout << endl;
cout << endl;
return 0;
}
/*double negativeSquare(double a,double b,double c)
{
int negCheck=((pow((b*b) + (4 * a*c), 0.5)) < 0);
return negCheck;
}*/
/*double quadCalculator(double a, double b, double c, double answerOne, double answerTwo)
{
return answerOne, answerTwo;
}*/
Explanation / Answer
#include<iostream>
#include<cmath>
using namespace std;
double negativeSquare(double &a,double &b,double &c);
double quadCalculator(double &a, double &b, double &c);
int calc(double a, double b, double c, double &answerOne, double &answerTwo);
int menu()
{
int m;
int coef;
bool menuflag = 1;
bool cin_flag = 1;
do
{
cout << " *-_-*-_-*| Guten Tag! |*-_-*-_-*-__ " << endl;
//cout << "How may I help you today: " << endl;
cout << endl;
cout << "To Give Me Your Coefficients Press:" << " < 1 >"<< endl;
cin.clear();
cin >> m;
cout << endl;
if (m == 1)
{
return 1;
}
else if (m == 2)
{
if (cin_flag == 0)
{
return 1;
}
cout << endl;
cout << endl;
cout << endl;
cout << "Not so fast, gimme some coefficients first " << endl;
cout << endl;
cout << endl;
cout << endl;
return 1;
}
else if (m == 3)
{
return 3;
}
else if (m == 1 || m == 2 || m == 3)
{
menuflag = 0;
}
} while (menuflag == 1);
return m;
}
double getDouble()
{
double num;
cin>>num;
return num;
}
int getInt()
{
int num;
cin>>num;
return num;
}
int calc(double a, double b, double c, double &answerOne, double &answerTwo)
{
double resultOne=((-b + ((pow((b*b) + (4 * a*c), 0.5)))) / (2 * a));
double resultTwo=((-b - ((pow((b*b) + (4 * a*c), 0.5)))) / (2 * a));
if(resultOne==answerOne&&resultTwo==answerTwo)
return 0;
else if(answerTwo<0||answerOne<0)
return 2;
else
return 1;
}
int main()
{
double a, b, c;
double answerOne;
double answerTwo;
double x, y, z;
int m;
int coef;
m = menu();
bool cin_flag = 0;
bool menuflag = 0;
if (m == 3)
{
cout << "Auf Wiedersehen!" << endl;
return 0;
}
do {
menu();
cout << "*-_-*-___|Hello and Welcome to the Almighty Quadratic Solver|__-*-_-*"<< endl;
cout << "*_-*-_-*-_-*-__|Don't panic we are here to Solve the Day|__-*-_-*-_-*"<< endl;
cout << " ****************|HOWEVER|***************"<< endl;
cout << " We require only two things from you: "<< endl;
cout << endl;
cout << " First, don't feed me a Zero coefficient as an input for A." << endl;
cout << endl;
cout << " Second, we just met, so how about we take it slow and start" << endl;
cout << " off with only numbers and nothing else, oh and by numbers I mean" << endl;
cout << " three coefficients ;-)." << endl;
cout << endl;
cout << endl;
if (m==1)
{
cout << "Ahem, so let's begin." << endl;
cout << " Please give me your first coefficient: " << endl;
a= getDouble();
if (a == 0)
{
cout << endl;
cout << endl;
cout << " Oh C'mon!" << endl;
cout << " What am I a schmuck on wheels!" << endl;
cout << " I'm outta here." << endl;
cout << endl;
cout << endl;
cout << endl;
return 0;
}
if (a == cin.fail())
{
cout << " ERROR: must be a valid number and non-zero." << endl << endl;
cin.clear();
cin.ignore();
return 0;
}
cout << endl;
cout << " Now, your second: " << endl;
b=getDouble();
if (b == cin.fail())
{
cout << " ERROR: must be a valid number and non-zero." << endl << endl;
cin.clear();
cin.ignore();
return 0;
}
cout << endl;
cout << " And lastly, your third: " << endl;
c=getDouble();
if (c == cin.fail())
{
cout << "ERROR: must be a valid number and non-zero." << endl << endl;
cin.clear();
cin.ignore();
return 0;
}
}
/*int check;
check = (pow((b*b) - (4 * a*c), 0.5));
cout<<check;
if (check<0)
{
cout << endl;
cout << endl;
cout << endl;
cout << " [Uh Oh]" << endl;
cout << " We have been informed that the numbas you gave us " << endl;
cout << " were inappropriate, thus, we cannot 'Solve the Day'."<< endl;
cout << " Yippee ki-yay!" << endl;
cout << endl;
cout << endl;
cout << endl;
return 0;
}*/
cout<<"Enter Coefficient 1 : "<<endl;
answerOne=getDouble();
cout<<"Enter Coefficient 2 : "<<endl;
answerTwo=getDouble();
int result=calc(a, b, c, answerOne, answerTwo);
if(result==0)
{
cout<<"Solutions are "<<answerOne<<" and "<<answerTwo<<endl;
}
else if(result==1)
{
cout<<"Non-Quadratic my man!"<<endl;
}
else if(result==2)
{
cout<<"Imaginary Roots!!!"<<endl;
}
} while (m == 1);
return 0;
}
/*double negativeSquare(double a,double b,double c)
{
int negCheck=((pow((b*b) + (4 * a*c), 0.5)) < 0);
return negCheck;
}*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.