Questions on this code

Hello everybody, I am new to the forums here and I have a few questions on this application I was coding to help me in Algebra a bit.
QUESTIONS
1)Is it ok to use goto like this? I am asking this because before on the forums I have seen other experienced programmers show strong dislike towards it.
2)Also, I know a lot of the experienced programmers on these forums show strong dislike towards system("pause"). Is there anything I could replace the system pauses with in this code (mac and pc compatible) to make it more efficient?
3)If the user is "untrustable" and doesn't type in what is expected from the computer (ex:They type in letters where the computer is asking for numbers) is there anything to use as a backup instead of having the program mess up?

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
107
108
109
110
111
112
113
114
115
116
117
118
119

#include <iostream>
#include <string>
using namespace std;

int main()
{
        string para_mxb;
	float m_1, b_1, y_1, x_1, mx;
        float m_2, b_2, y_2, x_2;
	float m, b, y, x;
	float y2, y1, x2, x1;
        float ap, bp, cp, yp, xp;
	string beganswer, beganswer_2;
beg:
    cout << "What kind of coordinates would you like to find? "
    << "Type in 'linear' for y=mx+b" << endl << "type in 'parabola' for ax²+bx+c: ";
    cin >> para_mxb;
    if (para_mxb == "parabola" || para_mxb == "Parabola")
{
    cout << "What would you like to do? "
	<<  "To find coordinates type in 'coord'" << endl;
    cin >> beganswer_2;
    if (beganswer_2 == "coord" || beganswer_2 == "Coord")
    {
        cout << "Please type in a: " << endl;
        cin >> ap;
        cout << "Please type in b: " << endl;
        cin >> bp;
        cout << "Please type in c: " << endl;
        cin >> cp;
        for (xp=-10;xp<11;xp++)
        {
            yp = ap*(xp*xp) + bp * xp + cp;
            cout << "(" << xp << ", " << yp << ")" << endl;
        }
    }
}
    else if (para_mxb == "linear")
{
	cout << "What would you like to do?"
	<< endl << "To find a slope type in 'slope'" << endl
	<<  "To find coordinates type in 'coord'" << endl
	<< "To find y intercept type in 'inter'" << endl
    << "To find x intercept type in 'xinter'" << endl;
	cin >> beganswer;
	if (beganswer == "slope" || beganswer == "Slope")
	{
		cout << "Enter y2: ";
		cin >> y2;
		cout << "Enter y1: ";
		cin >> y1;
		cout << "Enter x2: ";
		cin >> x2;
		cout << "Enter x1: ";
		cin >> x1;
		cout << "Slope is " << (y2-y1) << " / " << (x2-x1) << " or " << (y2-y1)/(x2-x1) << endl;
		system("pause");
		goto beg;
	}
	else if (beganswer == "coord" || beganswer == "Coord")
	{
		cout << "Enter m: ";
		cin >> m;
		cout << "Enter b: ";
		cin >> b;
		for (x=-10;x<11;x++)
		{
			y = (m*x) + b;
			cout  << "(" << x << ", " << y << ")" << endl;
		}
        system("pause");
		goto beg;
	}
	else if (beganswer == "inter" || beganswer == "Inter")
	{
		cout << "Enter y: ";
		cin >> y_1;
		cout << "Enter x: ";
		cin >> x_1;
		cout << "Enter slope: ";
		cin >> m_1;
		mx = m_1 * x_1;
		b_1 = y_1 - mx;
		cout << "The y intercept is " <<  b_1 << endl;
        system("pause");
		goto beg;
	}
    else if (beganswer == "xinter" || beganswer == "Xinter")
    {
        cout << "Enter m: " << endl;
        cin >> m_2;
        cout << "Enter b: " << endl;
        cin >> b_2;
        mx = b_2/ m_2;
        if (mx<0)
        {
            cout << mx << endl;
            system("pause");
            goto beg;
        }
        else if (mx>0)
        {
            cout << "-" << mx << endl;
            system("pause");
            goto beg;
        }
        else if (mx == 0)
        {
            cout << mx << endl;
            system("pause");
            goto beg;
        }
    }
}
	system("pause");
    goto beg;
	return 0;
}


Feel free to leave any comments or suggestions as well. Thank you.
Ok,
Let me answer quests 2&3.
system(); function in geeral is not trustable because, it calls an external programme...and what if that programme has been infected by a virus? Also, some anti-viruses detects programmes wih this particular function as threats.

Quest 3:
You would like to read more about the bad bit flag.
A quick example
1
2
3
4
5
6
7
8
9
10
11
int num;

cout<<"enter a number"; //prompts the user for a number
cin>>num;
if(cin.badbit())  //checks if the user entered anything apart from a number
{
 cout<<"wrong input";
 cin.clear();  //to clear the buffer
 cin.ignore();
}
else .....


HTH,
Aceix.
Thanks really appreciate it, however when I tried to use the code pasted above it shows an error for cin.badbit(). It says,

std::istream std::cin
OBJECTS

Error:expression preceding parentheses of apparent call must have (pointer-to-) function type
Last edited on
Topic archived. No new replies allowed.