How do I make a C++ program where it identifies the first repeating character?

0 votes
asked May 26, 2019 by anonymous
edited May 26, 2019

This is my work so far:

#include <iostream> //Including parts of code

#include <string>

#include <algorithm>

#include <string>

std::string input;        //Declaring variables

int A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z;

int capLetters[26] = {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z};

void counter_print(std::string input, char character,int value){ //Defining a function

  if(input.find(character) != std::string::npos){ //Identifies the letters




  std::sort(capLetters, capLetters+26,std::greater<int>());






int main(){

  std::cout << "\x1B[2J\x1B[H";

  std::cout<<"\n*****START PROGRAM******\nEnter a sequence of Capital letters. The program will identify which ones repeat.\n\n";




























  std::cout<<"\n\n*****END PROGRAM*****\n";

  return 0;


However, it doesn't give output. How do I edit it so it will work correctly?

2 Answers

+2 votes
answered May 28, 2019 by Pierre (320 points)

For the love of God, never copy/paste the same line twenty-six times! Use a loop:

int letterCount[26];

for(char c = 'A'; c <= 'Z'; c++)

         counter_print(input, c, letterCount[c - 'A']);

+1 vote
answered Apr 27 by gfrve dfss (340 points)
to make it easier, put the sentence
USING NAMESPACE STD and after no more need to add std ::
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.