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...
#include <iostream>
usingnamespace 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;
}
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?
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.
#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