Oh good god, I found out that there's a tutorial on the Start Page of Visual C++ 2k8 that explains how to create a freestanding program. Once again, I ask a question and it turns out that the answer was staring me in the face. My apologies!
If you opened this thread up and realized I already answered my own big question and are kind of ticked at wasting the time, well, I still have no idea how to cause this loop to continue just by having the user hit enter, so if you can help me figure that out I'd be grateful.
The loop in question is up here, and the rest of the code is provided below it for reference if it comes up.
Thanks again for the assistance, and apologies on the waste-of-space thread.
1 2 3 4 5 6 7 8 9 10 11 12 13
int main(){
char ans ='y';
cout << "Welcome to Quadratic Equation Solver." << endl;
//hitting enter does not actually continue the program
//I considered goto, but then I realized that I don't actually know
//how one uses goto, which is probably a good thing
while (!(ans == 'n')) {
Solver();
cout << "\nType n to quit, else hit enter: " << endl;
};
return(0);
};
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
#include <limits>
usingnamespace std;
class Quadex {
private:
double b, a, c, x, y;
char neg;
public:
void Write(int, double);
void Discri();
void Squaret();
void Display();
};
void Quadex::Write(int i, double bb){
if (i ==0)
a = bb;
elseif (i ==1)
b = bb;
elseif (i ==2)
c = bb;
};
void Quadex::Discri(){
x = ((b*b) - (4 * a * c));
cout << "\nThe discriminant is: " << x <<endl;
};
void Quadex::Squaret(){
if (x < 0){
neg ='i';
x = -x;
y = sqrt(x);
}
elseif (x >= 0) {
y = sqrt(x);
neg ='o';
}
};
void Quadex::Display(){
cout << endl;
string roots = "\nThe roots of the equation are: ";
if (neg =='o'){
double v = ((b * -1) +y)/(2*a);
double w = ((b * -1) -y)/(2*a);
if (v == w)
cout << "\nThe root of this equation is: " << v <<endl;
else
cout << roots << v << " and " << w <<endl;
}
elseif (neg =='i'){
double v = -1 * (b/(2*a));
if (v !=0)
cout << roots << v << " +/- " << (y/(2*a)) << "i" << endl;
elseif ((y/(2*a)) ==1)
cout << roots << "+/- i" << endl;
else
cout << roots << "+/- " << (y/(2*a)) << "i" << endl;
}
};
void Solver();
int main(){
char ans ='y';
cout << "Welcome to Quadratic Equation Solver." << endl;
//hitting enter does not actually continue the program
//I considered goto, but then I realized that I don't actually know
//how one uses goto, which is probably a good thing
while (!(ans == 'n')) {
Solver();
cout << "\nType n to quit, else hit enter: " << endl;
};
return(0);
};
void Solver(){
Quadex p;
int a;
for (int i=0; i<3; i++) {
if (i ==0)
cout << "What is the coefficient of x^2?" << endl;
elseif (i ==1)
cout << "What is the coefficient of x?" <<endl;
elseif (i ==2)
cout << "What is the constant?" << endl;
while (!(cin >> a)) {
cout << "err: invalid input please re-enter" << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
p.Write(i, a);
}
p.Discri();
p.Squaret();
p.Display();
};