Every time I run my program, the output in the first line of the do while loop repeats itself. So the output "Enter characters to add..." is output twice at the start of each loop. How do I make it only output once every loop repetition?
main file
#include "LinkedList.h"
#include "ListNode.h"
#include "Node.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
LinkedList<char> *setUpSentence() {
//allocate the linked list objet
LinkedList<char> *sentence = new LinkedList<char>();
char ch;
do {
cout << "Enter characters to add, enter full stop to finish adding." << endl;
ch = cin.get();
sentence->addAtEnd(ch);
} while (ch != '.');
return sentence;
}
int main() {
//call the function, store the returned pointer in sentence variable
LinkedList<char> *sentence = setUpSentence();
while(sentence->size > 0) {
cout << sentence->removeAtFront() << endl;
}
//delete to avoid memory leak
delete sentence;
}