Adak 419 Nearly a Posting Virtuoso

Since I did most of my beer-drinking at home, instead of at a uni, I'm not sure either, but I'm very sure I could solve it, and you can too.

Sometimes, you get to use a handy map to find your way around, and sometimes you have to just use the environment and "just fly the plane". This is the latter case. You will learn how to do it, by doing it. ;)

I'd start with making a struct for each row, with the state, the input a, and the input b, and sort them with input a and input b as keys (that is, if a's are tied, in two structs as you sort, then sort by input b to reach the sorted position. Now you're ready to go on your first matching input "hunt".

Take it step by step to cut the problem down to size. Use a paper and pen if you can't see your way through it yet. Start ASAP, because it always takes longer when you don't have a map to help out.

Adak 419 Nearly a Posting Virtuoso

You have a good compiler for this, because Turbo C has several extensions for working with text on the console window.

When I did this, I used a simple, oversized char array which was not the best design certainly, but it worked, and I was not interested in making a better one.

I believe you mean ANSI code, (that's the funny looking stuff with the weird chars in it). I'd avoid it like the plague.

It takes a good amount of work to get these things working right, so start in, ASAP. We won't code up your assignment for you - we help you with YOUR code you post and give specific info about (questions or problems).

Nothing more 99.9% of the time. Certainly NOT something this extensive.

Adak 419 Nearly a Posting Virtuoso

There may be a slick way to do this - sorta has that "smell" to it, but I don't know it.

Right now, I'd make a struct or use parallel arrays to sort the inputs by a and b (both). That will give you all matches of a and b pairs, immediaely. They'll be right next to each other. Be sure to shift the far left column of numbers, with every swap your program makes.

That makes searching for other matches very easy. Resort as needed. If you do this a few times by hand first, you'll find it worth your while as you code the program. I take it for granted that you have or will search Google, as well for this topic.

An interesting problem. I haven't seen that one before. Where is this type of problem solving used, Discrete Math?

Adak 419 Nearly a Posting Virtuoso

It's an old school type solution, but I used three int arrays. One for each of the two numbers' digits to go into, and one to hold the "carry" value.

Imagine they are stacked up on top of each other. One digit ONLY per element of each array. Any value > 9, puts the "carry value, into the carry array with the proper (next) index.

Work from the one's column (far right hand side), or you can make it a bit easier and reverse the number, and work from the left hand side (so the indices get bigger in the array's as you loop from first to last digit columns.

Start with a small 3 digit number and see which way you prefer and get the logic worked out, before you jump to bigger numbers.

The process is EXACTLY the same as if you were multiplying numbers together by hand, in grade school.

Laying it out first by hand, (pen and paper) a few times, is a worthwhile experience, since we're so used to using calculators all the time.

Adak 419 Nearly a Posting Virtuoso

In your binary search, the logic is wrong. If the word being compared is < target word (has a negative number returned from strcmp()), then you need to have the high brought down mid-1

And if the word being compared is > the target word, you need to have the low brought UP to mid+1.

So your binary search is completely backwards. Try it and see. Understand that the wrong logic wil occassionally find a word anyway, however.

Sorting by last name will be a problem because you don't have a lname field in your student struct - just name.

I would break it up to lname and fname, and make both char arrays. THEN you can sort by last name, otherwise you are sorting by whatever is first in the name field.

Adak 419 Nearly a Posting Virtuoso

You're using i and j to make your arrays before they have been given a value! Line 8.

Adak 419 Nearly a Posting Virtuoso

Different compilers, and OS's, have different sized buffers for handling this - and indeed, whether the buffer is used or not.

Linux, being based around Unix, has a larger buffer, I would hazard a guess at. Windows, being based around PC's with more modest resources, typically uses a smaller buffer.

The size of the buffer can be set as well as whether it's used or not - and makes a HUGE difference in performance. A program I had that required 14 seconds, (in Windows 7), immediately improved to just under 2 seconds, by changing the size of the vbuffer().

(The task required finding and writing out 50,000 prime numbers to stdout, using fwrite) printf() is quite different, and I have no experience with how it might be affected by this change in a buffer size.

Adak 419 Nearly a Posting Virtuoso

Celina, can you write out in plain English, a description of what you want, step by step:

1) get input - this is an example:
"example of input here"

2) process or calculate some here

3) give output like this, to a file with a numbered name, every 5 minutes
"example of output here" ------ fileN.rpt where N is the next number

4) do this 10 times.

something like that, but with clear examples of the input and output, etc.

General descriptions are OK for most things, but programming requires a great deal of specific details.

Adak 419 Nearly a Posting Virtuoso

DVD drive and fan control depends on the system and mobo/DVD drive, as well as your operating system. This is not like DOS where you can control everything you want, from your program. THAT was WAY too hacker/virus/malware friendly. Nowadays, anything you want to do like this, you do it through the operating system. That means the answer depends on the operating system you have.

Same with system shutdown. You can't have a rogue program shutting down computers all over, whenever they want.

Adak 419 Nearly a Posting Virtuoso

If you don't know C's most basic operations, one questions what you're doing working with credit card validation algorithms or code.

Hmmmmm.

Adak 419 Nearly a Posting Virtuoso

You're cluttering up your code in the while loop. Set an input function up, and just call it. Either sort the input there as well, or set a sort function up, as well.

Kudo's for using a Shell sort - modern cpu's have really raised it's stock options, and your indentation is excellent, also.

Then I see line 105: :( Don't do that.

The binary search should be in a separate function, and return either mid (found at index number), or -1.

Just want to repeat Tumlee's advice: Post up your errors and warnings, and ask specific questons with details. We can't see what you have seen, and need it.

Adak 419 Nearly a Posting Virtuoso

But the question remains :"Is there a consistent relationship between phase angle and voltage?", because these other things you have mentioned, are not all relevant to creating a best software algorithm.

I agree completely that hardware can do all this a lot faster, but that might be expensive and may not even be practical, I'm not sure. For a good software algorithm, we need more of the relavent info.

In your hardware, what is the relationship between the phase angle and voltage? Does it vary? By how much?

If there is a good relationship between phase angle and voltage consistently, then which is easier to read for you? If it's consistent, we can get data from several runs, and see clearly what is the best setting.

Otherwise, we are making suggestions that are sub optimal.

Adak 419 Nearly a Posting Virtuoso

Dean, he's posted this thread on at least 3 programming boards, and received code and the most detailed software and hardware discussion on another board.

He's had at least 4 algorithms and several snippets of code given to him, already. He wants code - and he's been given code, but doesn't want to work with it, apparently.

If the voltage at the phase angles were to stay contant for the angle, then it becomes a simple matter of testing some values, sorting the values you recieve, and a binary search would be very fast look up to find the perfect phase angle.

But that's not the case. He needs minimum testing, since he needs the answer within 2 seconds, and each test takes 100 milliseconds. So the question becomes, what's the stability of voltage to phase angle, over time? Is it consistent, or does it vary? And by how much?

He's been advised to have the tester changed to continuous testing mode, which is much faster, after looking at the data for the tester he has. He says the hardware "guy" is reluctant or unwilling to make that change.

Without consistency info, you can't design the absolute best algorithm for the software, but he's been given several excellent one's, including code for some of them.

Go to CBoard C forum, for that discussion. I wouldn't spend more time on it, although the problem is intriguing.

Adak 419 Nearly a Posting Virtuoso

Try this. (It works, but you'll need to adapt it a bit).

I changed d to divv, and c to cur. You need to include <math.h> for sqrt() (big time saver).

Be sure to initialize biggest to zero, before the loops start.

//two is handled separately, before this

         for (divv = 3; divv < sqroot; divv+=2) {
            if (cur % divv == 0) { // I have treid c % d too.
               isprime = 0;
               //printf("cur: %d  div: %d \n",cur, divv); getchar();
               break;
            }

         }
         if (isprime == 1) {      //is cur a factor of NUM?
            if(NUM % cur == 0 && cur > biggest) {
               biggest = cur;
               //printf("cur: %lu  div: %lu \n",cur, divv); //shows biggest cur's
            }
         }

      printf("biggest: %lu"\n,biggest);
      return 0;
Adak 419 Nearly a Posting Virtuoso

Line 14 is an example of your problem, for all your for loops:

for ( i = 1; i <= NUM_VALUES; i++ )

Which is wrong. correct is:

for ( i = 0; i < NUM_VALUES; i++ )  

You need to MEMORIZE this idiom! This is C, and C has zero based array!

Adak 419 Nearly a Posting Virtuoso

The heart of games is usually a BIG do while or while loop. You probably will want to call other functions, but they always return to the BIG game loop.

So start with a BIG game loop, and see how far you can go. When/if you get stuck, post your code, and tell us what has you stuck. BE SURE TO HIGHLIGHT YOUR CODE AND CLICK ON the Code tab of the editor to insert that program, as code, not html text. (which is almost unreadable for code)

Leave out the details you can, for now. Work on the basic logic or "flow" of the program. If you actually play the game with paper and pen a time or two, it will greatly help you to see the kinds of logic you'll need.

Adak 419 Nearly a Posting Virtuoso

I don't understand the problem of getting info from inside the switch statement. It's the same as getting info from anywhere else in main().

Adak 419 Nearly a Posting Virtuoso

void functions like eReturn, don't return anything, so putting the word "return" in there, is completely superflous.

And you can only return one item from a function. If you need more, I'd send it to the function as a pointer in the parameter. Say I want to return i and sum. I could do it this way:

int myIvariable, sum=0;

myIvariable = myFunction(&sum); //sending the address of sum
//now myIVariable has the value of i from myFunction(), and sum has a new value, also.
printf("myIvariable: %d,  sum: %d \n",myIvariable, sum);

int myFunction(int *sum) { //*sum is now the sum amount and "sum" is a pointer
   int i;
   for(i=0;i<22;i++) //a simple for loop
      *sum += i;

   return i;
}

If that doesn't help you, run through a C tutorial (there are scads of them on the net), because this is a very important concept in C.

Adak 419 Nearly a Posting Virtuoso

Line #102, remove the &
I would consider changing phno to a string, because it's possible that an integer would overflow with a long phone number - just a suggestion however.

You didn't ask any questions, so I'm not sure what to answer otherwise.

void main() should always be int main() with a return of 0, btw. That tells you (if you want), wether the program ran to completion or had a run-time failure.

Adak 419 Nearly a Posting Virtuoso

OK, keep going! Sounds like you're on a roll. ;) If you have a specific question, be sure to post your latest code - otherwise I'm blind to your changes.

Adak 419 Nearly a Posting Virtuoso

There is no output of the customer info, so what do you need? Number of days, and name of the client, and the type of vehicle would seem required minimum.

Do you need anything else from the custome? Maybe address, payment type, or ???

Adak 419 Nearly a Posting Virtuoso

Do you need to print out one customer's details at a time, as they rent a car, or do you need to print out EVERY customer's details, maybe at the end of the day or week?

I'm trying to see what you need for your output - one customer details output at a time, or several at a time?

Adak 419 Nearly a Posting Virtuoso

Do that before you print up vowstr[]. Then, before you enter another string to be analyzed, you need to also set vowstr[] to "". Right now you are keeping the old vowels from the last string that was entered.

Just to be safe, maybe:

for(i=0;i<sizeof(vowstr);i++)
   vowstr[i]='\0';

Then you know the last strings vowels are gone and can't zombie back to life.

Adak 419 Nearly a Posting Virtuoso

The letters in vowstr[] are not a string - they're just a bunch of letters at this time. If you want to print them out as a string (or do any other string operation with them), you have to add the end of string marker char: '\0', just beyond the last letter in vowstr[].

If you want to enter another string, you need to first, set vowstr[0]='\0' (set it to NULL char).

Adak 419 Nearly a Posting Virtuoso

Line 21, add a space before the %c: scanf(" %c",&wordlength). That is needed to "eat" the newline that was left over in the input buffer, from when you hit enter.

Adak 419 Nearly a Posting Virtuoso

You can't use [i] as your index in vowstr[]. i is tied to the entire string that was entered.

BTW, you could have done all this in a single for loop. ;)

Add int m=0, and then use vowstr[m++] instead of vowstr[i], in the if statement

Adak 419 Nearly a Posting Virtuoso

You've done a LOT of work here! :)

I couldn't even locate your code for deleting a record, however. There's no need to actually delete every record you want removed - sounds odd, but if you edit their name and make it "", you can then add a small bit of logic to your program, so it ignores records with no name.

Why do that? Because you don't want to move data around - you want it to stay where it is. The risk might be small, but your data can become garbled and useless, by moving it around a lot. So leave the "deleted" record in place, but take out the name by putting an empty string or end of char marker ( '\0' ), into the first char of the persons name.

Now that record should be seen as available by your program, for a new record's data, for all fields.

I'll just add that void main() is an error - it's always int main with a return of 0 to the operating system, and as you may know, your program has a crazy number of gotoxy() calls in it, that are not necessary!

This is how you don't want to code:

 }
}
}
}
}

That ruins the readability of your program - don't do that. There are programs like "astyle.exe" that will format your code correctly for you, automatically, and it's free!

Your functions should be designed around what they DO, and …

Adak 419 Nearly a Posting Virtuoso

You can simply download an ASCII table - I got mine from lookuptables.com I believe. google it and you'll see a lot to choose from. Get one that includes their hex value.

I keep it as a gif on the desktop - very handy. 30h is not a binary value, of course.

Adak 419 Nearly a Posting Virtuoso

gotoxy(int x, int y), moves the console cursor to the designated column and row, on your monitor. It is one of the functions defined in the header file "conio.h".

My compiler prepends an underscore to all non-standard functions, so _gotoxy(), insted of gotoxy(). (conio.h is popular, but not part of the C standard).

Adak 419 Nearly a Posting Virtuoso

Your prototype for getdate is this:
void get_date(int holder, int day, int month, int year);

But the function itself, says:
void get_date(int holder, int *day, int *month, int *year);

Which has the compiler giving errors to you. Make your prototype the same as your function's first line, and you'll be seeing much fewer errors and warnings.

Note that getch() is in conio.h iirc. You could use getchar(), however. (Which returns an char, but it's an int really. Confusing, I know.

Adak 419 Nearly a Posting Virtuoso

Since I probably confused you, with the above, this is an example:

Note that my compiler is Pelles C, and gotoxy() is referred to as _gotoxy(), since it is a non-standard function.

    #include <stdio.h>
    #include <math.h>
    #include <conio.h>

    #define v1 3 //Velocity at Beach
    #define v2 1.5 //Velocity in Water

    int main()
    {
    int count=0,minTTRow=0; 
    float Xo=0, a=0, b=0,minTT=0.0;
    float c=0, distanceA=0, distanceB=0, timeA=0, timeB=0, totaldistance=0, totaltime=0, totaltimeold=0, totaltimenew=0;
    printf("Give the value of Xo min: ");
    scanf("%f", &a);
    printf("Give the value of Xo max: ");
    scanf("%f", &b);
    printf("Give the range between the values: ");
    scanf("%f", &c);
    printf("Xo\tDistance A\tDistance B\tTime A\tTime B\t Total distance A+B\t Total time A+B\n");
    printf("________________________________________________________________________________\n\n");

    minTT=99999.99;     //impossibly high value
    for(Xo=a; Xo<=b; Xo=Xo+c)
    {
      distanceA = sqrt((20*20) + (Xo*Xo));
      timeA = distanceA/v1;
      distanceB = sqrt(30*30 + (50-Xo)*(50-Xo));
      timeB = distanceB/v2;
      totaldistance = distanceA + distanceB;
      totaltime = totaltimeold;
      totaltimeold = totaltimenew;
      totaltimenew = timeA + timeB;
      count++;
      if(totaltimenew < minTT) {
         minTT=totaltimenew;
         minTTRow=count;
      }

     if((totaltime==0 && totaltimeold!=0 && totaltimenew>totaltimeold) || (totaltimeold<totaltimenew && totaltimeold<totaltime )) printf("x"), Xo=Xo+c;
        printf("%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t\t%.2f\t\t%.2f\n", Xo, distanceA, distanceB, timeA, timeB, totaldistance, totaltimenew);
    }
    _gotoxy(64,minTTRow+6);
    printf("X");
    _gotoxy(1,count+6+2);   

    getchar();
    getchar();
    return 0;
}
Adak 419 Nearly a Posting Virtuoso

Add a new float variables, minTTnew. On line 19, set minTTnew to a ridiculously high value, beyond anything your data would reach - maybe 9999.999, (or include limits.h file and use FLOAT_MAX for your system).

Then on line 35, put
if(totaltimenew < minTTnew)
minTTnew = totaltimenew;

Also, add an int counter, set to zero, on line 19. Inside the for loop, on line 34, add this:

counter++;

Now you have to count out your column on the screen, for totaltimenew. Say it's 62, for example. and say the first row with a totaltimenew printed on it, is row 10.

So now you need to add this, after the entire for loop, say line 39:

gotoxy(61,10+counter);
and print the 'x' char.

If you have the include file conio.h, include it for gotoxy(). If not, and you're on Windows, you can use setConsoleCursorPosition(), after including windows.h. If you're on Linux, you can use ncurses (which is like conio.h).

It's a bit difficult, only because your data is not arranged in an array of structs - then it would be easy - but that will come later in learning C.

Adak 419 Nearly a Posting Virtuoso

1) You have to get the format of the pixel, in that type of picture - and there are many types of greyscale. You can google the format.

2) Make the number of variables (and type - probably unsigned char, but it could be int), you need, to correspond to your pixel's format.

3) write out the new data with the changes you made. Don't try to actually alter the file, in place.

Adak 419 Nearly a Posting Virtuoso

Show your current output, and also an example of what you want. Looking at your code, I can't see what your description is describing. I'm in a mash up here. ;)

BE SURE TO USE CODE TAGS around these examples, so the forum software won't mangle the spacing of them!

Adak 419 Nearly a Posting Virtuoso

You could extend your current program by changing int q to unsigned long (or unsigned long long if your compiler supports it).

The goal of course, is that you will have to work out a way to multiply using int arrays, however. (you could use char arrays for the digits, but I prefer using int arrays)

Do you remember how to multiply by hand? You know, what school kids learned in the 4th or 5th grade, back when dinosaur's walked the earth? ;)

Take out a paper and pen, and see how you could mimic that school kid arithmetic, using arrays. I used 4: one for the multiplicand (bet you haven't heard THAT word since forever, that's the top number's digits), one for the multiplier digits, one for the carry, and one for the answer.

They make libraries (bignum from GNU is well known), but it's a great exercise to build your own little function.

In 10 minutes, you'll see the multiplying pattern you need to follow, using the arrays, while you work at it with paper and pen. That's the pattern your program's logic will use, as well.

Give that a shot!

Adak 419 Nearly a Posting Virtuoso

You need to specify what these "details of the customer", are. They we'll show you how to make a struct to tie all them together, into one record.

what data types are these details, how many details are there, and what do you want to name their variables?

Adak 419 Nearly a Posting Virtuoso

Move line 6 to line 4, so your variables are being created just once, outside the loop, (we're big on recycling, hey!) <smile>

Instead of a getch(), make it a scanf() for the value of again, and do it like this (NOTE THE SPACE BEFORE THE % !)
printf("Add another two numbers? [y/n]: ");
scanf(" %c",&again);

Without the space before the %c, the newline in the input buffer (from previously pressing the enter key), will cause a lot of trouble with a char scanf(), making it look like it got "skipped".

Adak 419 Nearly a Posting Virtuoso

Well, void main() should be int main(void), with a return 0 at the end of it (in main).

Having all your code in main() is awkward, you should break it up into fucntions. Usually, every option in the switch statement, gets a new function.

And then you need a big do while loop for the menu itself (which should probably be in a separate function), so the menu can show itself for the next customer, without having to be restarted.

Post up your questions and problems - it's good to see your code (essential really), but people can't respond to problems that you haven't brought up, or answer questions you don't ask.

Good start though. I like the use of the switch statements, and your indentation makes it easy to read your code - so that's a very good start.

Adak 419 Nearly a Posting Virtuoso

I doubt if anyone here knows what the specs are for VB graphics to emulate it precisely. Google "graphic libraries for C", and you should come up with something - there are several - some simple, some for only certain operating systems, etc.

Adak 419 Nearly a Posting Virtuoso

SHOW me an example of what you want for output of a game, and I'll tell you how to get that output.

Ubuntu console is just fine, and I know it's for school, and if you knew how to do it, you wouldn't be asking about it, here.

No problem. I'm here to help.

Adak 419 Nearly a Posting Virtuoso

You can save it any way you like. In Sudoku, we save the grid as an 81 char string, with no line breaks. It's hard to understand it from looking at it outside the game configuration, but it allows us to save a TON of still readable grids, in a relatively small space.

Your options are anything you like - ideally, it would be in a format that you could share games with others interested in the game. Is there a standard format that's used for this game? Try Googling and see if you find a popular format.

Adak 419 Nearly a Posting Virtuoso

First thing is to be able to read the data in the file. To do that, you need to know the way the data is organized, in the file.

Run through a C tutorial on opening files, and reading from them, into an array of some kind - the kind depends on the data. While you're searching for tutorials in C, go to Wikipedia, and read up on Bubble sort and Insertion sort. Wiki has every major sort fully described.

Adak 419 Nearly a Posting Virtuoso

The first thing you need to know, is what format the data in the file, will be in. The more variety this is to the format, the more logic you will need to have, since every possible format that is found in the data file, must be handled appropriately.

So, what is the format, and what do you want done with it (put it into an array, a linked list, a queue, a stack, etc.)?

Adak 419 Nearly a Posting Virtuoso

You have an earnest attitude, Sachi. Keep it up, and it will carry you far.

Adak 419 Nearly a Posting Virtuoso

On line 62 and 64, you are returning prematurely - after the first name search fails.

You need to put those returns at the very bottom of the function. To return more data from the function you need to send in another parameter, a pointer, so the variable it holds the address of, can be modified, and available in the calling function.

You could also put it into a struct, but I won't advise it.

Adak 419 Nearly a Posting Virtuoso

First, be aware that your code is C++, and you are compiling it (obviously) with a C++ compiler, instead of the C compiler.

This answer works in C, but you may need to adapt it to work with C++. Sachi's code is also C, since this is the C forum.

If this is the way your data is laid out:

sachi 12345 M 60000009009
sahu 1233 F 76578
happy 6456 M 34536363636

Then the simple way to find a name is to use code similar to this:

First, you need to #include <string.h>, so you can use strstr().

char *ptr;
char target[120]; //over-sized is good
printf("Name to search for: ");
scanf("%s",target);
char oneLine[120];    // ditto
while((fgets(oneLine, 120, theFilePointerName)) != NULL) {
   ptr = strstr(oneLine, target);
   if(ptr) {
      printf("Customer was found\n%s\n",oneLine);
      found++;
   }
}

if(!found) {
   printf("Customer was not found\n");
}

No one should be using gets() anymore, btw. Way too unsafe (and has been deprecated). If the data is in the proper record format, you should be using that, or working with the data based on entire rows at a time, not working with getchar(), in my judgement.

You'll find working with C much easier if you stop using your C++ compiler and asking questions about C++ code, in the C forum. ;)

You will want to adjust the code to your needs - maybe stop the search when the name is first found, perhaps use sscanf() on oneLine to put the record into the struct, …

Adak 419 Nearly a Posting Virtuoso

It's OK to be somewhat stubborn, but when you're wrong, is not the time. Of course, they're built to different standards, they're years apart, and from different lineages, as well.

Don't be that silly student who uses a different compiler than his teacher, because he "has preferences". ?? This is not speed dating!

Get with the program.

Adak 419 Nearly a Posting Virtuoso

Not scanf("%c", &someVariable), but scanf(" %c", &someVariable);

The %c format needs a space before it, to "eat" the newchar char, and get past it.

Adak 419 Nearly a Posting Virtuoso

In my tests, you have the fastest Sieve of Eratosthenes, while keeping it with that algorithm. I tried four different optimizations, but they did nothing to speed it up - and at least one, actually slowed it down.

Even in the IDE, your program runs in 1.77 seconds or so, on my PC. There are other ways to (maybe) make it faster, but then it becomes something else, not a Sieve of Eratosthenes program, at all.

So, take the next step, and enter it at SPOJ, in this classic problem:
http://www.spoj.pl/problems/TDKPRIME/

This is a beast of a problem, even with a good Sieve program, but we'll see if it gets accepted. (that is, if it passes the stiff time requirement, with the right answers). You have a lot of other code to add to this, to make it work correctly with the input the program needs to work with.

But it should be fun.

Adak 419 Nearly a Posting Virtuoso

That isn't what we do here. ;)

We help YOU when you are stuck with some C programming problem, but we don't supply algorithms or large blocks of code for you, on request.

You get started on your program, and if you hit a problem you can't solve, then you post the code (so we know what you're talking about), and give the specifics of your problem.

Then we can nearly always help.

And do you REALLY require an algorithm to count up the positive numbers from a set?

Please -- say it ain't so!