I want to take inputs as long as the user enters '#' in while loops.
I implemented the while algorithms seen below, and the first one actually works. But the program does not enter the second while loop. What I saw while debugging is that, in a function, only one while(cin>> ....) algorithm works, and it automatically ignores the second one.
Is there a solution to fix this? How can I make the second while loop not be ignored?
void addTransaction(transactionNode* blockchain)
{
string owner, sendTo="";
int transactionId=0, outLocation=0, amount=0, tid;
tid = blockchain->tid;
transactionNode* newT = new transactionNode(++tid, owner, 0, 0, nullptr, nullptr, nullptr); // created a empty transaction Node for the new transaction
cout << "Input the owner of the transaction: " << endl;
cin >> owner;
newT->owner = owner; // updated the name
cout << "Write the input list in form of 'transactionId_1 outLocation_1 transactionId_2 outLocation_2 #' put # after all the inputs finish: " << endl;
while (cin>> transactionId >> outLocation) // takes the inputs until '#' is entered
{
insertAtEndforinputNode(newT->inputList, transactionId, outLocation); // adds the new input node to the end of the inputList in our current transaction
}
cout << "Write the output list in form of 'amount_1 sentTo_1 amount_2 sentTo_2 #' put # after all inputs finish: " << endl;
while (cin>> amount>> sendTo)
{
insertAtEndforoutputNode(newT->outputList, amount, sendTo);
}
}
Aucun commentaire:
Enregistrer un commentaire