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 6763021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:25:38+00:00 2026-05-26T14:25:38+00:00

was looking over this program and im trying to figure out how to search

  • 0

was looking over this program and im trying to figure out how to search for letters in an array instead of numbers, it works for numbers but how can i make it work for letters. please help…………… here is the code

#include <iostream>
using namespace std;
const int DECLARED_SIZE = 4;

void fillArray(int a[], int size, string& letter);
int search(const int a[], string letter, string target);

int main( )
{
    int arr[DECLARED_SIZE]; string listletter; string target;
    fillArray(arr, DECLARED_SIZE, listletter);
    char ans;
    int result;
    do
    {
        cout << "Enter a letter to search for: ";
        cin >> target;
        result = search(arr, listletter, target);
        if (result == -1)
            cout << target << " is not on the list.\n";
        else
            cout << target << " is stored in array position "
            << result << endl
            << "(Remember: The first position is 0.)\n";
        cout << "Search again?(y/n followed by Return): ";
        cin >> ans;
    } while ((ans != 'n') && (ans != 'N'));
    cout << "End of program.\n";
    return 0;
}

void fillArray(int a[], int size, string& letter)
{
    cout << "Enter up to " << size << " letter.\n"
        << "Mark the end of the list with a negative number.\n";
    int next, index = 0;
    cin >> next;
    while ((next >= 0) && (index < size))
    {
        a[index] = next;
        index++;
        cin >> next;
    }
}

int search(const int a[], string numberUsed, string target)
{
    int index  = 0; 
    string run = "run";
    bool found = false;

    while ((!found)) // && (index < numberUsed))
        if (target == run)
            found = true;
        else
            index++;

    if (found)
        return index;
    else
        return -1;
}
  • 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-05-26T14:25:39+00:00Added an answer on May 26, 2026 at 2:25 pm

    I noticed you’re loading an int in fillArray. You need to use char if you want character input.

    void fillArray(int a[], int size, string& letter)
    {
     cout << "Enter up to " << size << " letter.\n"
     << "Mark the end of the list with a negative number.\n";
     char next;
     int index = 0;
     cin >> next;
     while ((next >= 0) && (index < size))
     {
       a[index] = next;
       index++;
     cin >> next;
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking over the internet for a while about this, but it
Looking over the magento 1.5 schema I cannot seem to figure out how a
I've been trying to figure out how to send and receive XML Data over
I'm trying to write a program that outputs data that can be served over
I was looking over this code to calculate math.sqrt in Java. Why did they
I have been looking over this code for the past hour, I cant see
I am looking at nServiceBus and came over this interface namespace NServiceBus { public
I've been looking for this extra div for over 5 hours and am at
I'm trying to figure out the best programming language for an analytical model I'm
I've been trying to figure out what computer field I want to go into

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.