Exforsys
+ Reply to Thread
Results 1 to 3 of 3

this program is to take in any syring from a user and print out the number of occurances of each cha

This is a discussion on this program is to take in any syring from a user and print out the number of occurances of each cha within the C and C++ forums, part of the Programming Talk category; #include <iostream> #include<string> using namespace std; char alphabet[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; void letterOccurance(string news); string word; void main() { cout<<"Enter the word"<<endl; cin>>word; ...

  1. #1
    loctovia is offline Junior Member Array
    Join Date
    Apr 2011
    Answers
    2

    this program is to take in any syring from a user and print out the number of occurances of each cha

    #include <iostream>
    #include<string>
    using namespace std;

    char alphabet[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
    void letterOccurance(string news);
    string word;
    void main()
    {
    cout<<"Enter the word"<<endl;
    cin>>word;
    strupr(string);
    // letterOccurance((word.upperCase)string)
    }

    void letterOccurance(string news)
    {

    int occur =0;
    int i=0;
    char alphabet;
    for(int j=0;j<news.length;j++)
    {
    if alphabet[i]==(string.charAt (j))
    {
    occur=occur+1;
    }
    cout<<"letter "<<alphabet[i]<<"has "<<occur<<"occurances "<<endl;
    }
    }


  2. #2
    swapwarick's Avatar
    swapwarick is offline Member Array
    Join Date
    Mar 2011
    Location
    Pune,India
    Answers
    37
    Wat are u trying to do? The program u wrote is wrong! Write a new 1 with proper declarations!!


  3. #3
    Sudheer Kethavarapu is offline Junior Member Array
    Join Date
    May 2011
    Answers
    5
    wht u wrote the code is wrong. u need to count the occurance then display the value finally.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...