Design a program that prompts the user for a word, and then prompts the user for a letter. Your program should count the number of times the letters entered appear in the word, and then continue prompting for new letters. The program should list the letters found.
Hint: Declare a Boolean array of size 26 to track whether a letter has been found.
using namespace std; //main function int main() { string word;//input word char letter;//input letter bool letterfound[26];// letter found
cout<<"Enter word: ";//show enter word cin>>word;//read word from keybord for(;;){/input letter again and again cout<<"Enter letter: ";//show enter letter int countnumberoftimes=0;//count& for number of& letter is in word cin>>letter;//input letter for(int i=0;i<word.length();i++){//from 0 to length of letter do if(word[i]==letter){//if ltter is in word then countnumberoftimes++;//incriment& countnumberoftimes letterfound[i]=true;// letterfound& set true } } //show& number of times the letters entered appear in the word is cout<<"The number of times the letters entered appear in the word is: "<<countnumberoftimes<<"\n"; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment