need help with finding the occurrence

I need to write a program that reads a line of text from input and then return the number of times that the word "code" appears.I am allowed to use any loop, substr() and at() to locate substrings and individual characters in the line of input.can also use the length(). Please help
Show us your code, and we'll help.

If you're stuck for how to start, begin by reading the input line of text into a string.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;

int main()
{
    // Input
    cout << "Enter a string : ";
    string str;
    getline(cin, str);

    int count = 0;

    //REST OF MY CODE SHOULD APPEAR HERE  ----------------------

    // Output
    cout << "A variation of \"code\" appears " << count << " times." << endl;

}


output should be like this

Enter a string: aaacodebbb
A variation of "code" appears 1 times
How do you know that a variation of "code" appeared 1 time? Translate the steps you took into code.

I'd imagine it's something like:

Look at first letter. If it's not 'c', move on and start again.
If it was 'c', look at next letter. If next letter is not 'o', move on and start again.
If it was 'o', look at next letter. If next letter is not 'd', move on and start again.
If it was 'd', look at next letter. If next letter is not 'e', move on and start again.
If it was 'e', you've found an instance of the "code". Add on to total, move on and start again.

This is what coding is. Not memorising syntax. Understanding how to solve a problem within the limitations of the machine and translating it into code.
Topic archived. No new replies allowed.