need help with loop

Can someone please tell me whats wrong with this code it won't run at all


/*Problem Statement
Write a program that will ask the user to input a
word that is at least 5 characters in length. Once
a valid word has been inputted, ask the user to
input a character. The program will then
calculate the number of times this inputted
character appears in the word and output the
result. */
#include <iostream>
#include <string>
using namespace std;

int main ()
{
// Ask the user to input a word while the word length is <5

string word = "";

do{
cout << "Enter a word that ha at least 5 characters: " << endl;
cin >> word;
}while(word.size()<5);

// Ask the user to input a character

char searchCH = '0';
cout << "Enter a character and the program will tell you how many times it appears in the word" << word <<"." << endl;
cin >> searchCH;

int counter = 0;

// Iterate over the word

for (int i = 0; i < word.size(); i++)
{
// Get a character

char ch = word.at(i);

// If the character matches the character we're looking for

if (searchCH == ch)
{
// Increment a counter
counter++; //counter = counter + 1
}

}
// Output the number of times the character was found in the word
cout << "The number of " << searchCH << "'s in the word " << word <<" is " << counter <<".\n";

return 0;
}
Last edited on
int mani ()

The name of the function should be main
still not working

it says:
warning comparison between signed and unsigned integer expression (-wsign-compare)

and shows a red dot next to:
for (int i = 0; i < word.size(); i++)
Last edited on
it's fixed now
Topic archived. No new replies allowed.