Why won't input read first double?

solved
Last edited on
closed account (D80DSL3A)
Why do you read a single character in first? Lines 19, 20:
1
2
char expression;
  cin >> expression;

This is what's removing the 1st character (1). Line 30 cin >> value; then gets 2 as the first double value.

Side note. Is your program behaving OK on exit? Your Dstack destructor looks like it would cause an infinite loop or a crash:
1
2
3
4
5
6
7
8
Dstack::~Dstack()
{
  Node *tmp;// never assigned a value
  while ( m_head != NULL)// m_head isn't going to change here.
  {
    delete tmp;// delete what?
  }  
}

Perhaps you haven't had a problem yet if all nodes are already popped when your program exits. Do the same as you did in pop() except there's no need to involve value.
1
2
3
4
5
6
7
8
9
10
Dstack::~Dstack()
{
  Node *tmp;
  while ( m_head != NULL)
  {
    temp = m_head;
    m_head = m_head->m_next;
    delete temp;
  }  
}
Topic archived. No new replies allowed.