dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Help please

  1. #1
    Join Date
    Dec 2008
    Posts
    2

    Help please

    Hello,
    I am taking a class in C++ and I am having problems understanding some things, I really hope you can help me. I was having problems grasping arrays so I started doing examples right out of the book and for the most part it is working but this program, copied from the book exactly, doesn't seem to work and I was hoping someone could tell me what the problem is or what I am missing....thanks and I am sorry if I am asking stupid questions.

    Brian

    #include<iostream>
    using namespace std;
    main(){
    char ch;
    int freqletter[200];
    for(ch='a';ch<='z';ch++){
    freqletter[ch]=0;}//initialize the array
    cout<<"Enter some lower case letters(Ctrl+Z to End):";
    while(cin>>ch){
    freqletter[ch]=freqletter[ch]+1;}
    cout<<"\n\n\n\t\tLETTER FREQUENCY"<<endl<<endl;
    int lineCounter=1;
    for(ch='a';ch<='z';ch++){
    cout<<" "<<ch<<"="<<freqletter[ch];
    if(lineCounter>=5){
    cout<<endl;
    lineCounter=0;}//IF
    lineCounter++;}//FOR
    cout<<endl;
    return 0;
    system("pause");
    }//MAIN

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,561

    Re: Help please

    Try again. Next time, use code tags, white space, indentation and be specific about what the problem is.

    Read and follow the guidelines here.

  3. #3
    Join Date
    Dec 2008
    Posts
    2

    Re: Help please

    Sorry,
    I attached the program and what is happening is it will compile with no errors but once I run the program it will ask me to input my letters, which I do, and then it doesn't do anything. The program doesn't end it doesn't give any output it just goes to the next line and allows me to keep inputing letters.

    Brian
    Attached Files Attached Files

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,561

    Re: Help please

    I don't see how this loop will ever terminate.
    Code:
           while(cin>>ch){
                          freqletter[ch]=freqletter[ch]+1;}

  5. #5
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,116

    Re: Help please

    You did not follow GCDEF's very good suggestions, nor apparently did you bother to take a few minutes to read the FAQ's on using code guru (otherwise you would not have posted such a meaningless title.

    As far as specifics, What line is it looping on (as viewed in the debugger)? What are the states of the variables that are causing it to loop (again viewed in the debugger)?
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)