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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:40:49+00:00 2026-06-11T02:40:49+00:00

I saw an older post on here asking how to do relatively the same

  • 0

I saw an older post on here asking how to do relatively the same thing, but their approach was different and i’m interested to know the hole in my program.

I am attempting to write a program that accepts characters into a 10 character length array. I want the program to evaluate the first array position and delete any duplicates it finds later in the array by identifying a duplicate and moving all of the values to the right of it to the left by one. The ‘size’ of the array is then decreased by one.

I believe the logic I used for the delete function is correct but the program only prints an ‘a’ for the first value and the fourth value in the array.

Any help would be greatly appreciated, here is my code:

#include <iostream>
using namespace std;

int letter_entry_print(int size, char array[10]);
int delete_repeats(int& size, char array[10]);
int final_array_print(int size, char array[10]);

int main()
{
    char array[10];
    int size = 10;

    letter_entry_print(size,array);
    delete_repeats(size,array);
    final_array_print(size,array);

    cout<<"\n";
    system("pause");
}

int letter_entry_print(int size, char array[10])
{
    int i;

    for (i=0;i<size;i++)
    {
        cout << "Enter letter #" << i+1 << endl;
        cin >> array[i];
        cout << "\n";
    }

    cout << "\nYour array index is as follows:\n\n";

    for (i=0;i<size;i++)
    {
        cout << array[i];
        cout << " ";
    }

    cout <<"\n\n";
    return 0;
}

int delete_repeats(int& size, char array[10])
{
    int ans;
    int loc;
    int search;
    int replace;
    char target='a';

    cout << "Enter 1 to delete repeats.\n\n";
    cin >> ans;
    if(ans==1)
    {
        for(loc=0;loc<size;loc++)
        {
            array[loc]=target;
            for(search=1;search<(size-loc);search++)
            {
                if(target=array[loc+search])
                {
                    for(replace=0;replace<(size-(loc+search));replace++)
                    {
                        array[loc+search+replace]=array[loc+search+replace+1];
                        array[size-1]=0;
                        size=(size-1);
                    }
                }
            }
        }
    }else(cout<<"\nWhy didn't you press 1?\n\n");
    return 0;
}

int final_array_print(int size, char array[10])
{
    cout<<"\nYour new index is as follows:\n\n";
    int i;
    for(i=0;i<size;i++)
    {
        cout<<array[i];
        cout<<" ";
    }

    cout<<"\n";
    return 0;
}
  • 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-11T02:40:51+00:00Added an answer on June 11, 2026 at 2:40 am

    Ok, there are a few things about your code that look odd.

    1) you repeat 10 all over the place to the point where there’s no way you could resonably change it, but you also pass size along. Instead of making all your functions take arrays of 10 chars, consider just passing in a pointer to char, like:

    int final_array_print(int size, char *array)
    

    then you can change the size of your arrays more easily. There’s no point in passing size everywhere if you’re going to limit yourself forever to 10 items, and there’s no good reason to pass arrays of 10 items around if you provide a size!

    2) ok, so now you want to look for duplicates. Why do you overwrite the first element in your array with an ‘a’?

     char target='a';
    ...
    array[loc]=target;
    

    wouldn’t you want to do it the other way around?

    3) next, as @Mahesh points out, you probably want to use the comparison operator ‘==’ rather than the assignment operator = when looking for duplicates that is:

    if(target=array[loc+search])
    

    should probably be

    if(target == array[loc+search])
    

    4) Next, dontbeafraidtousealittlewhitespacebetweenyourwordsandpunctuation.Itmakesitaloteasiertoidentifytypingmistakesandspellingerrors.

    5) your loop to actually perform the replacement has incredibly complicated indices. It would be easier if you didn’t start with replace = 0, but just start at replace = search + 1, try it out and perhaps you’ll how much simpler all the rest of the indices become.

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

Sidebar

Related Questions

I saw this post but didn't understand if this was the same issue. My
I saw some code when studying the open source project: here . But I
I already saw this post here (http://stackoverflow.com/questions/1398113/sql-select-one-row-randomly-but-taking-into-account-a-weight), but couldnt work it out. Where do
I saw a question which is asking designing algorithm for Post-order Tree Walk without
I saw the docs on the Instagram developers page. http://instagram.com/developer/endpoints/ But I want to
I saw that even by writing separate commands, we can combine two different types
I saw many threads with this tittle, but no one really speak about reuse
I saw a similar question being posted here, yet it did not help me
Ok i saw many post's on how to serialize the value of dragged items
I saw this question on one of the job postings and its asking what's

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.