counters..omg :S

This is a discussion on counters..omg :S within the C++ Programming forums, part of the General Programming Boards category; check this piece of code out: Code: for(int u=1;u<=5;u++){ inta=(a+(u-1)*f); intb=a+u*f; for(int r=0;r<n;r++) if(w[r]>=inta && w[r]<=intb) count++; cout << "\t("<<inta<<","<<intb<<") ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    28

    counters..omg :S

    check this piece of code out:
    Code:
    	for(int u=1;u<=5;u++){
    		inta=(a+(u-1)*f);
    		intb=a+u*f;
            
    		for(int r=0;r<n;r++)
    		if(w[r]>=inta && w[r]<=intb)
    			count++;
    			
    		cout << "\t("<<inta<<","<<intb<<")  " << count<<endl;
    }
    ive always sucked using multiple for's, but what i wanna do is count the number of times w[r] appears in the given (inta,intb) interval while u is 1,2,...5, individually (as in how many for 1, how many for 2, and so on)
    but what i have here adds 1 to count for all u's.
    so when i run the proggy i end up with count being 20, while in reality it should be a lot less :S

    any thoughts? thx
    the early bird gets the worm but the second mouse gets the cheese

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    28
    ok nevermind, fixed it
    i knew it had to be something stupid, i just initialized the counter to 0 after the cout

    WOOT me so happy - proyect is done D : D

    thx to all 8)




    Code:
    //kinda got excited there :P
    the early bird gets the worm but the second mouse gets the cheese

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [C] Best way to save matrix counters
    By Nazgulled in forum C Programming
    Replies: 7
    Last Post: 03-24-2006, 04:02 PM
  2. Omg Last Time I Swear!
    By unejam2005 in forum C++ Programming
    Replies: 3
    Last Post: 12-12-2005, 11:49 PM
  3. array of counters
    By luigi40 in forum C# Programming
    Replies: 3
    Last Post: 12-11-2005, 01:25 AM
  4. Having trouble with counters
    By tameeyore in forum C Programming
    Replies: 30
    Last Post: 10-08-2004, 02:14 PM

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