Could someone tell me what's wrong with my script?

I've been looking at it for awhile and I think if a someone else takes a fresh look at it, it might help identify the problem. I'm making a small calculator. It's a simple script, but kinda long. I know it can be shorter. By the way, I just prefer it to be long and simple, then compressed and complex. The issue is that it will only do addition.
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 <math.h>


using namespace std;

int main()
{
    
    {
           char a,s,x,r,p,d,;
           a = 'a'; 
           s = 's';
           x = 'x';
           r = 'r';
           p = 'p';
           d = 'd';
           markerA:        
          cout << "Enter 'a' for Addition" << endl << "Enter 's' for Subtraction" << endl;
    cout << "Enter 'x' for Multiplication" << endl << "Enter 'd' for Division" << endl;
    cout << "Enter 'p' for Powers" << endl << "Enter 'r' for Square Root" << endl;
    cout << "Please disragard the quotes" << endl;
    cin >> d,p,r,x,s,a;
    

           if
           (a == 'a')
          {goto markerB;}
            if
            (s == 's')
            {goto markerC;}
            if
           (x == 'x')          
            {goto markerD;} 
            if
            (d == 'd')
            {goto markerE;}
            if
            (r == 'r')
            {goto markerF;}
            if
            (p == 'p')
            {goto markerG;} 
          
           {
                 markerB:
         double w, b, c,;
    cout << "Please enter the first number" << endl;
    cin >> c;
    cout << "Please enter the second number" << endl;
    cin >> b;
    w = b + c;
    cout << w << endl;
    goto markerA;
    }
    
 
            {
                  markerC:
                 double t, e, f;
                 cout << "Please enter the original number" << endl;
                 cin >> t;
     cout << "Please enter the number that will be taken away" << endl;
                 cin >> e;
                 f = t - e;
                 cout << f << endl;
                 goto markerA;
                 }
            
                  
                          
                          {
                           markerD:       
                      double g, h, i;
                      i = g * h;
                      cout << "Please enter the first multiple" << endl;
                      cin >> g;
                      cout << "Please enter the second that multiple" << endl;
                      cin >> h;
                      cout << i << endl;
                      goto markerA;
                      }
                      
                      {
                             markerE:
                           double j, k, l;
                           l = j/k;
       cout << "Please enter the number that will be divided into" << endl;
                           cin >> j;
        cout << "Please enter the number that will be going into " << j << endl;
                           cin >> k;
                           cout << l << endl;
                           goto markerA;
                           }
                           
                           {
                                  markerF:
                                
                                     double m, n;
                                     n = sqrt(m);
 cout << "Please enter the POSITIVE number you want the square root of" << endl;
                                     cin >> m;
                     cout << "The square root of" << m << " is " << n << endl;
                                     goto markerA;
                                     }
    
          {
           markerG:
          
          double v, y, z;
          cout << "Please enter the original value" << endl;
          cin >> v;
          cout << "Please enter the exponent value" << endl;
          cin >> y;
          z = pow (v,y);
          cout << z << endl;
          goto markerA;
}}} 
you want to take the input and see how that compares to the letters. In your case, a will always = 'a'
also, in some cases you find the solution before you put the input in the variables, giving wrong answers.
Last edited on
but wouldn't the
cin >> d,p,r,x,s,a;
in line 23 change the value of each character?
No, those are different variables, and that's not how you do multiple inputs. You can chain them like cin >> d >> p >> r >> x >> s >> a, but I don't know what you want to do with that. And you code could be much simpler with a switch. Gotos should generally be avoided.

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
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
	char input;
	double a, b;
	while (true) {
		cout << "Enter 'a' for Addition" << endl << "Enter 's' for Subtraction" << endl;
		cout << "Enter 'x' for Multiplication" << endl << "Enter 'd' for Division" << endl;
		cout << "Enter 'p' for Powers" << endl << "Enter 'r' for Square Root" << endl;
		cout << "Please disragard the quotes" << endl;
		cin >> input;
		switch (input) {
			case 'a':
				cout << "Please enter the first number" << endl;
				cin >> a;
				cout << "Please enter the second number" << endl;
				cout << (a + b) << endl;
				break;
			case 's':
				cout << "Please enter the original number" << endl;
				cin >> a;
				cout << "Please enter the number that will be taken away" << endl;
				cin >> b;
				cout << (a - b) << endl;
				break;
			case 'x':
				cout << "Please enter the first multiple" << endl;
				cin >> a;
				cout << "Please enter the second that multiple" << endl;
				cin >> b;
				cout << (a * b) << endl;
				break;
			case 'd':
				cout << "Please enter the number that will be divided into" << endl;
				cin >> a;
				cout << "Please enter the number that will be going into " << a << endl;
				cin >> b;
				cout << (a / b) << endl;
				break;
			case 'r':
				cout << "Please enter the POSITIVE number you want the square root of" << endl;
				cin >> a;
				cout << sqrt(a) << endl;
				break;
			case 'p':
				cout << "Please enter the original value" << endl;
				cin >> a;
				cout << "Please enter the exponent value" << endl;
				cin >> b;
				cout << pow(a, b) << endl;
			default:
				break;
		}
	}
}
Last edited on
Ah, thank you. I didn't know anything about breaks. I'll look them up now.
And there was a minor error at line 19. You left out cin >> b;
Topic archived. No new replies allowed.