Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8731759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:18:41+00:00 2026-06-13T09:18:41+00:00

Say I get user input. If what they type in is not already in

  • 0

Say I get user input. If what they type in is not already in the array(how do I check an array?), add it to the array.
And vice versa how do I remove something from an array given the user input.

Example:

string teams[] = {"St. Louis,","Dallas","Chicago,","Atlanta,"};

cout <<"What is the name of the city you want to add?" << endl;
    cin >> add_city;

 cout <<"What is the name of the city you want to remove?" << endl;
    cin >> remove_city;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:18:43+00:00Added an answer on June 13, 2026 at 9:18 am

    Using an array, you could treat empty array cells with a char* such as “EMPTY”. To find an item you search through the array , and find to “replace” or add it.

    const char * Empty = "EMPTY";
    cout << "Please enter a city you want to add:"
    cin >> city;
    for(int i = 0; i < Arr_Size; i++) //variable to represent size of array
    {
        if(Arr[i] == Empty) //check for any empty cells you want to add
        {
           //replace cell
        }
        else if(i == Arr_Size-1) //if on last loop
           cout << "Could not find empty cell, sorry!";
    }
    

    As for removing a cell:

    cout << "Please enter the name of the city you would like to remove: ";
    cin >> CityRemove;
    
    for(int i = 0; i < Arr_Size; i++)
    {
        if(Arr[i] == CityRemove)
        {
            Arr[i] = Empty;             //previous constant to represent your "empty" cell
        }
        else if(i == Arr_Size - 1)    //on last loop, tell the user you could not find it.
        {
            cout << "Could not find the city to remove, sorry!";
        }
    }
    

    Printing the array while skipping the ’empty’ cells
    //Printing the array

    for(int i = 0; i < Arr_Size; i++)
    {
        if(Arr[i] != Empty)             //if the cell isnt 'empty'
        {
            cout << Arr[i] << endl;
        }
    }
    

    But i do agree using a vector would be a much more efficient approach, this is simply a creative approach to get your mind thinking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a text <INPUT> for a user's name and they decide to
The scenario is that a user should get notification (say via typical JS alert
Alright, so i'm not sure if im converting user input time to GMT properly.
I'm wondering why php adds a backslash when i remove double quotes. <input type=text
Let's say I have a form_tag in a view gathering a view user input
Say you get a file handle from some outside DLL and instantiate a FileStream
I am a beginner in Knockout and I must say I often get confused
Say you just want to get rid of the changes you've made to one
lets say you want to get all the columns of a table, but exclude
lets say i use jquery.get to retrive a website to string and how am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.