64 642
Assignments Done
99,2%
Successfully Done
In September 2018

Answer to Question #26283 in C++ for huzaifa

Question #26283
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.
Expert's answer
#include <conio.h>
#include <iostream>
#include <string>

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";
}

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions