Results 1 to 19 of 19

Thread: Tri-Nested for loop

Threaded View

  1. #1

    Thread Starter
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Tri-Nested for loop

    I can't get this to work right. I have been workiing on it for a long time now but to no avail. It is a 3 section nested loop (if there is such a thing). It is supposed to print out a graph for each score but when it runs it just prints out
    *
    *
    *
    *
    *
    and I don't know what it prints out before that because it moves so fast and then it ends.

    Am I doing something wrong?
    Code:
    cout << "SCORE" << setw(13) << "FREQUENCY" << setw(13)<< "GRAPH"<< endl;
    // Score output loop
         for (int score=1; score < 10001; score++){
         for (;(frequency[score]>1) && (frequency[score]< 10001);)
         cout<< setw(5) << score << setw(5) << frequency[score] << setw(5);
    // Print bar
                for (int i=1; i <= frequency[i]; i++)
                cout <<"*";
                cout << endl;
         }
    I did have

    if (!(frequency[i]==0)) cout << "*";
    cout << endl;

    after

    cout<< setw(5) << score << setw(5) << frequency[score] << setw(5);

    instead of the 2nd for loop.
    But the problem was that if reads any other statements as else. But I wanted it to go back up to for to increment the number again.

    One of my biggest goals is to stop it from printing 0's.
    Last edited by aewarnick; Jan 7th, 2003 at 09:56 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width