How do I get the things I write to work on other peoples computers?

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);
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <cmath>
#include <string>
#include <sstream>
#include <limits>

using namespace 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;
	else if (i ==1)
		b = bb;
	else if (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);
	}
	else if (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;
	}

	else if (neg =='i'){
		double v = -1 * (b/(2*a));
		if (v !=0)
			cout << roots << v << " +/- " << (y/(2*a)) << "i" << endl;
		else if ((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;
		else if (i ==1)
			cout << "What is the coefficient of x?" <<endl;
		else if (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();
};
Last edited on
while (!(ans == 'n')) {

Did you mean '\n'?
I think he meant the character 'n' (press n to quit).
firedraco wrote:
Did you mean '\n'?

No, he just forgot a cin.get(ans); after the output statement.
Last edited on
Topic archived. No new replies allowed.