Hi guys, first off this is not a homework assignment. During my break from school I am trying to learn some more c++. I am trying to write a program that uses a string and that is supposed to have the user enter a string, then enter a char, then the program is supposed to tell you how many times the char you entered is in the string you typed.(example - the string i enter is "hey whats up" and the char i enter is "h", the program is supposed to tell me that "h" occured 2 times). The book I am using tells me that I should use a loop that starts the index value at 0 then changes the index to one value passed the index where char was found (which is confusing to me).
I am having a hard time with this one..help would greatly be appreciated. Below is some code I have so far. please help me out. thank you
I don't really know what to put below the for statement. Thanks guysCode:#include <iostream> #include <string> using namespace std; int main () { string message; char letter; int numletter; int i; cout << "Enter a message\n"; getline(cin, message); cout << "Enter a letter\n"; cin >> letter; numletter = message.find(letter); for (i = 0; i <= numletter; i++) system ("pause"); return 0; }