0
I made a data structure algorithm. I put all my knowledge into it. I can’t find the error. I leave the statement of the year below:
Make a program that creates two rows F1 and F2, size 10, each. Read 20 whole numbers, and if the number read is even, enter it in the queue F1 and, if odd, row F2. In sequence, if the number read is multiple of 3, remove an item from row F1 by storing it in a auxiliary variable and then write it in the video and insert it in row F2. If the number read is a multiple of 5, remove an item from row F2, storing it in an auxiliary variable and then writing it in the video and enter it in row F1. A number can be either a multiple of 3 or 5 and, in this case, present a message in the video and do nothing at queues, moving on to reading the next issue. Stop reading when the 20 numbers have already been read or when overflow occurs or underflow in some queue.
int main()
{
int f=-1, r=-1, f1[10], f2[10], cont=0, val=0, aux=0, tam=9;
do{
cout << "Informe um valor: " << endl;
cin >> val;
cout << " " << endl;
if(val%2==0){
if(r==tam){
cout << "OVERFLOW!" << endl << endl;
return 0;
}else{
f1[++r]=val;
}
}else{
if(r==tam){
cout << "OVERFLOW!" << endl << endl;
return 0;
}else{
f2[++r]=val;
}
}
if(val%3==0){
if(r==f){
cout << "UNDERFLOW!" << endl << endl;
return 0;
}else{
aux=f1[f+1];
f++;
if(f==r){
f=r=-1;
cout << "Valor retirado: " << aux << endl << endl;
f2[++r]=aux;
}
}
}
if(val%5==0){
if(r==f){
cout << "UNDERFLOW!" << endl << endl;
return 0;
}else{
aux=f2[f+1];
f++;
if(f==r){
f=r=-1;
cout << "Valor retirado: " << aux << endl << endl;
f1[++r]=aux;
}
}
}
if(val%3==0 && val%5==0){
cout << "Numero mulitplo de 3 e 5!" << endl << endl;
}
cont++;
}while(cont < 20);
return 0;
}
What error does it present ?
– Isac
I’m not able to write the lines. And the result is not expected
– Euronymus
That statement is a little strange at least. Because if you enter the number 3 theoretically you are right in 2 cases, the odd being is multiple of 3, which would remove an element from the
F1
to theF2
and inserted another toF2
. This also implies that you cannot start with an odd number otherwise you have nothing to remove fromF1
– Isac
Yeah. I couldn’t quite figure it out either!
– Euronymus
And the same thing happens for a multiple of 5 that has to be odd if it ends in
5
or even if it ends in10
. I advise you to try to review the statement with the teacher to clarify the objective of the work and how it is supposed to work.– Isac
I’ll talk to him. Thank you very much!
– Euronymus