I really don't know what's going on, it's a simple list exercise and the while is failing me, it doesn't matter what value I enter, it doesn't work, keep running the program and create infinite lists, I've already tried changing the value, putting different equal, and a thousand more ways, but I don't know what it could be, if someone tells me why, even if I put another = 0, the program continues to run, I would really appreciate it ;D
#include <iostream>
using namespace std;
struct Nodo
{
int info;
Nodo *sgte;
};
int main()
{
int valor, otra=1;
cout << "Ingrese el valor de la primer lista" << endl;
cin >> valor;
Nodo *lista=new Nodo();
Nodo *paux=new Nodo();
lista->info=valor;
lista->sgte=new Nodo();
paux = lista->sgte;
while (otra=1)
{
cout << "Ingrese el valor para la siguiente lista" << endl;
cin >> valor;
paux->info=valor;
cout << "Quiere ingresar otra lista? Toque 1, si no, toque 0" << endl;
cin >> otra;
if (otra=1)
{
paux->sgte=new Nodo();
paux=paux->sgte;
}
else
{
paux->sgte=NULL;
}
}
return 0;
}
Good day,
In everyday life there are two types of operations in which we use the word "equal"
If we say:
We are saying that x obtains the value of 2, that is, we are assigning the value of
2
ax
There is another "equal" which is when we compare two things or objects, in spoken language we also say: If x is "equal" to 2, then...
But in programming it is different, because now we are not assigning a value, but we are comparing
When comparing, as in the case of a
if
we have to use==
if(x==2)
It would be translated into spoken language as: Ifx
it is equivalent/equal to2
then...So your code needs to put the
==
inif
and it will work