Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- string word = "";
- do
- {
- cout << "Enter a word that has atleast 5 Chars lenght." << endl;
- getline(cin, word);
- } while ( word.size() < 5);
- char searchCh = '0';
- cout << "Enter a character and the program will tell you how many character there is in te word: " << word << "." << endl;
- cin >> searchCh;
- int counter = 0;
- for(int i=0; i < word.size(); i++)
- {
- char ch = word.at(i);
- if(searchCh == ch)
- {
- counter++;
- }
- }
- if (counter == 0)
- {
- string answer = "";
- cout << "No characters were found in the word " << word << "." << "would you like to repeat? Y/N";
- cin >> answer;
- if (answer == "Y" || answer == "Yes")
- {
- cout << "Okay.. rebooting.";
- main();
- }
- else if (answer == "N" || answer == "No")
- {
- cout << "Exiting..";
- return 0;
- }
- else
- {
- cout << "The number of " << searchCh << "'s in the word " << word << "is " << counter << ".\n";
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement