program

This is a discussion on program within the C++ Programming forums, part of the General Programming Boards category; how to find a letter "a" is repeated that many times in a given word or name.please send me a ...

  1. #1
    sve
    sve is offline
    Registered User
    Join Date
    Apr 2010
    Posts
    9

    program

    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

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,888
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    10
    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";
    }

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,888
    Quote Originally Posted by Mr. AB
    Check this program
    A quick check reveals that it is quite bad:
    • 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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21