Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reversing Queue Condensed Version() {

Posted on 2004-10-21
3
Medium Priority
?
321 Views
Last Modified: 2010-07-27
// Need to input multiple integers and get them returned in reversed order.  This code does not print in reverse.

#include <iostream>
#include <stack>

using namespace std;


int main(void)
   {
   stack<int> IntStack;
   int Num;

   cout << "Enter an integer (or CTRL z to end data entry): ";
   cin >> Num;

   while(! cin.fail())
      {
      IntStack.push(Num);
      cout << "Enter an integer (or CTRL z to end data entry): ";
      cin >> Num;
      }

   cout << endl << "The numbers in reverse order are:" << endl;
   while (! IntStack.empty())
      {
      Num = IntStack.top();
      IntStack.pop();
      cout << Num << endl;
      }

   return 0;
   }

0
Comment
Question by:edelossantos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
wayside earned 2000 total points
ID: 12384923
???

This code worked fine for me:

Enter an integer (or CTRL z to end data entry): 1
Enter an integer (or CTRL z to end data entry): 3
Enter an integer (or CTRL z to end data entry): 5
Enter an integer (or CTRL z to end data entry): 7
Enter an integer (or CTRL z to end data entry): 9
Enter an integer (or CTRL z to end data entry): ^Z

The numbers in reverse order are:
9
7
5
3
1
0
 

Author Comment

by:edelossantos
ID: 12395826
[edeloss2@pegasus exp]$ a.out
Enter an integer (or CTRL z to end data entry): 1
Enter an integer (or CTRL z to end data entry): 2
Enter an integer (or CTRL z to end data entry): 3
Enter an integer (or CTRL z to end data entry): 4
Enter an integer (or CTRL z to end data entry): 5
Enter an integer (or CTRL z to end data entry): 6
Enter an integer (or CTRL z to end data entry): 7
Enter an integer (or CTRL z to end data entry): 8
Enter an integer (or CTRL z to end data entry):
[1]+  Stopped                 a.out

// why am I getting this output?
0
 
LVL 14

Expert Comment

by:wayside
ID: 12399204
Your shell is set up to suspend the process when you press control-Z.

I found I could press almost any control character such as control-A to break out of the input loop. Try different ones, if none work for you, I would rework the input loop to look for a certain character such as a . (period) to break out of the input loop.

You could also change the suspend character of your shell, but that seems a little drastic.

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question