how to find a letter "a" is repeated that many times in a given word or name.please send me a simple program in this
how to find a letter "a" is repeated that many times in a given word or name.please send me a simple program in this
Please comply with the homework guidelines.
By the way, I think that your statement is ambiguous: are you trying to count how many times 'a' appears, or are you trying to find a string of 'a's of some given length?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Check this program
Code:#include<iostream.h> void main() { int count=0; char name[15]; cout<<"Enter name:"; cin>>name; for(int i=0;name[i]!="\0";i++) { if((name[i]==65)||(name[i]==91)) { cout++; } } cout<<"Number of times a appear="<<count"; }
A quick check reveals that it is quite bad:Originally Posted by Mr. AB
- The code lacks proper indentation.
- <iostream.h> should be replaced by <iostream>
- void main should be replaced by int main
- The names cout and cin are not qualified, yet there is no relevant using declarations or directive.
- The reading of input is susceptible to buffer overflow.
- name[i]!="\0" attempts to compare a char with a const char[2].
- 65 and 91 are magic numbers.
- cout++; is a true WTF, though excusable since cout and count are very close in edit distance.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)