asking question about negative variables...

im trying to make a kinda complex algorithm....


this algorithm will use a bunch of goto statements inside two for functions

for (int a=0; a<=b; a++)


not lets say i have a for statement like that.... i want a at -1 for one of the
for functions....

reason for this is a goto statement will be placed into one of the functions to go to the end of anotehr function completing a loop restarting the function making a complete loop out of two functions....

i just have the question how to make a integer value variable negative to make this loops logic right... or at least to my knowledge right...
this is my program.... i switched it to while loops but still isn't working

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>
using namespace std;

int aa[4], bb[4];

int main() 
{

int a, b, c;

int e, f, g;
e = f= g = 4;

a = 0;
while ( a <=e) 
{
if (a == 5)
goto five;
one:
cout << "Enter a number:";
cin >> aa[a];
a++;
goto two;

three:
continue;
}
two:
b = 0;
while ( b<=f)
{
if (b == 5)
{
goto five;
} 
cout << "Enter a number:";
cin >> bb[b];
b++;
goto three;
}
five:
int l;
int q;
int ddd=0;
int dddd=0;
for (l = 0; l<=ddd; l++)
{
for (q = 0; q<=dddd; q++)
{
int ans = aa[l] + bb[q];
cout << "Row one is " << ans << endl;
}
}

return 0;

}
closed account (z05DSL3A)
What are you trying to achieve? It looks like you have two arrays aa and bb, you are filling the arrays with number and then sitting in a loop adding element of each array to each other..."Row one is "...are you trying to do a 2d Array?
You really shouldn't be using so many goto statements, it makes your code very difficult to understand. Your code appears similar to the other thread you have (which is coded much, much better without using goto)

Hmm.. are you trying to make the program jump back and forth between the 2 while loops for each iteration?
closed account (z05DSL3A)
Now that I have seen your other post[1] I think I can see what you are trying to do. Using goto to jump in and out of other control structures is a bad idea.

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
#include <iostream>

int main()
{
    using std::cout;
    using std::cin;
    using std::endl;

    enum {limit = 3}; 
    
    int a[limit] = {0};
    int b[limit] = {0};
 

    int i(0);
    for(i = 0; i < limit; ++i)
    {
        cout << "Please enter a number for a[" << i << "]: ";
        cin  >> a[i];

        cout << "Please enter a number for b[" << i << "]: ";
        cin  >> b[i];
    }


    for(i = 0; i < limit; ++i)
    {
        cout << "The Sum of row a[" << i << "] b[" << i << "] is " << a[i]+b[i] << endl;
    }
}


output:
Please enter a number for a[0]: 1
Please enter a number for b[0]: 1
Please enter a number for a[1]: 2
Please enter a number for b[1]: 2
Please enter a number for a[2]: 3
Please enter a number for b[2]: 3
The Sum of row a[0] b[0] is 2
The Sum of row a[1] b[1] is 4
The Sum of row a[2] b[2] is 6





[1] http://www.cplusplus.com/forum/beginner/11107/
wow thanks that is what i was trying to do....
thanks all... and sorry it took so long to get back i program once every blue moon lol(like every 2 days...)
Topic archived. No new replies allowed.