Here is the question: Write a program that creates a queue of Strings and allows the input of an integer value n, followed by n names to be placed in the queue. Then the program should execute a loop that performs the following:
1 It displays the name in the front of the queue and asks the user to specify a number of names to be deleted. The user specifies a value and it deletes that number of names.
2 Each name deleted is displayed on the screen.
3 The two steps are continued until the queue is empty.

My problem here is that when i run the code i enter 3 names. But when it comes to delet the names if i enter 3 all the will be delet and the program works correctly but if i enter 1 so that i try to delete 1 by one it shows me the same name that is being deleted each time and when the last name is deleted the program stop working. Any help how i could correct it?

here are my codes:

#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main()
    int n,b=1;
    string x[10000];
    int i,c;

    cout<<"Enter the number of names:";

 queue <string> names;
 cout<<"Enter the names to be placed in the queue:"<<endl;


  b++ ;


cout<< "The person at the front of the queue is " <<names.front()<<endl;
cout<< "Enter a number of names to be deleted: ";
cout<< "The person got deleted is " <<x[i]<<endl;
 cout << "There are currently " << names.size () << " people in the queue" << endl;

    return 0;

Some of this makes no sense. You've got a queue of strings, so what's that array for? When you delete a name from the queue, you're showing the user somethig from the array? Why? Get rid of the array and just work with the queue.

This article has been dead for over six months. Start a new discussion instead.