Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*PROBLEM STATEMENT CHALLENGE (FROM YOUTUBER)*/
- //Ask the user to input a word while the word length < 5
- string word = "";
- wordCounterMachine:
- do{
- cout << "Enter a word that has atleast 5 characters: " << endl;
- cin >> word;
- }while(word.size() < 5);
- //Ask the user to input a character
- char searchChar = '0';
- cout << "Enter a character and the program will tell you how many times it appears in the word " << word << "." << endl;
- cin >> searchChar;
- int counter = 0;
- //Iterate over the word
- for(int i = 0; i < word.size(); i++)
- {
- //Get a character
- char ch = word.at(i);
- //If the character matches the character we're looking for
- if(searchChar == ch)
- {
- //Increment a counter
- counter++; //counter = counter + 1;
- }
- }
- //Output the number of times the character was found in the word
- cout << "The number of " << searchChar << "'s in the word " << word << " is " << counter << ".\n" << endl;
- system("pause");
- goto wordCounterMachine;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement