Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. string word = "";
  9.  
  10. do
  11. {
  12. cout << "Enter a word that has atleast 5 Chars lenght." << endl;
  13. getline(cin, word);
  14. } while ( word.size() < 5);
  15.  
  16. char searchCh = '0';
  17. cout << "Enter a character and the program will tell you how many character there is in te word: " << word << "." << endl;
  18. cin >> searchCh;
  19.  
  20. int counter = 0;
  21.  
  22. for(int i=0; i < word.size(); i++)
  23. {
  24. char ch = word.at(i);
  25. if(searchCh == ch)
  26. {
  27. counter++;
  28. }
  29. }
  30.  
  31. if (counter == 0)
  32. {
  33. string answer = "";
  34. cout << "No characters were found in the word " << word << "." << "would you like to repeat? Y/N";
  35. cin >> answer;
  36. if (answer == "Y" || answer == "Yes")
  37. {
  38. cout << "Okay.. rebooting.";
  39. main();
  40. }
  41.  
  42. else if (answer == "N" || answer == "No")
  43.  
  44. {
  45. cout << "Exiting..";
  46. return 0;
  47. }
  48. else
  49. {
  50. cout << "The number of " << searchCh << "'s in the word " << word << "is " << counter << ".\n";
  51. return 0;
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement