need a little help..

Hello :) im starting to learn c++... I have been given two tasks to do for my class. i made first one. it was to write a program that finds the middle letter of word.

But now i need to modify it that it would count how many words in a string has that letter? Please help?..

#include <iostream>
#include <string>
using namespace std;

string middle(string str) {
int i = str.length();

if ((i % 2) == 0) {
return str.substr(i/2 - 1, 2);
return str.substr(i/2, 1);

int main() {
string input;

cout << "Enter a word to print the middle character: ";
cin >> input;
string result = middle(input);

cout << "The middle char is: " << result << endl;
return 0;
What if the word have even number of characters, can you place the entire exercise statement?
Topic archived. No new replies allowed.