Arrays. Please, help.

How can I do this:

Making a program that capture a name and place of last in an array of string which must be kept on a rolling cycle and capturing the above so that the new is the last and the first to be removed or taken out of the arrangement.

Note: My English is not so good. Thank you.
Hmm well interpreting this post is kind of challenge, but it sounds like you're wanting a queue-type data structure.
My teacher told me I was done with 3 lines of code, but I have no idea how to do it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
#include <queue>

using namespace std;

int main()
{
  string name;
  queue<string> name_q;

  // Get the name(s) from the user.
  cout << "Enter name(s). Enter an empty line to finish.\n";  
  while(getline(cin, name) && !name.empty())
    name_q.push (name);

  // Print the name(s) in the queue.
  cout << "There are " << name_q.size() << " elements in the queue. They are: \n" ;
  while (!name_q.empty())
  {
    cout << name_q.front() << "\n";
    name_q.pop();
  }
  
  cout << '\n';
  return 0;
}
Last edited on
Topic archived. No new replies allowed.