You can use the following thought process in solving similar problems in the future.
Programming can be simplified into performing 3 steps:
1) input data 2) process data 3) output data
Steps:
1) Understand what you are trying to solve at your input.
you understood that you have to read in input using "cin" and store it using a string variable and then count the number times a character appears in that string.
2) Learn more about the variable type/class that you are using to store your input.
In your case you are storing your input in a "string", which is of a string class/type. Go to C++ reference website to read about string class and familiarize yourself with all the functions and attributes that string class provides. See the following link: In there you will see, that string class has "[ ]" operator that returns a character. You can click on that link and see the example on how to use it.
Next, use the information you just gained to process your data.
3) Now implement your logic to process data.
In your case, you can run a for loop:
std::string str; std::cin << std::str; int counter = 0; for(int i=0; i< str.size();i++) { if( str[i] == 'p' ) counter++; }
The if block checks every character in the string and matches it with 'p' character. If it matches, counter variable is incremented by 1. At the end, the value of "counter" is the number of times "p" appeared in the string "str"
std::string: cplusplus.com/reference/string/string which should help with your task. Note that the list also highlights other things you could do instead0, and then iterate over the string and add to the counter variable every time the current character is'a'or'c'