Solved

Counting Items in an Array

Posted on 2000-04-03
3
239 Views
Last Modified: 2010-04-02
I'm stomped.  I have to write a C++ program that creates an array of part numbers and prices.  The program must be equipped with an error function that seperates valid part numbers (within preset parameters) from invalid part numbers.  I think I have it relatively bug free except I need to know the series of commands that counts the actual items within an array.  Specifically, I need my program to count the amount of times a part number that was entered is valid and the amount of part numbers that are invalid.  Your help will be greatly appreciated.  Also, if you know where I can find various examples of C++ array code, that would be great.
0
Comment
Question by:nploving
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 2681392
obviously we don't know how to seperate good numbers from bad, you'll have to do that, but the code woudl be something line

const int MaxItemCount = 100;
int PartArray[MaxItemCount];
int GoodCount = 0;

for (int i =0; i < MaxItemCount; ++i)
{
   if  (PartNumberIsGood[i])
      ++GoodCount;
}

// GoodCount is now the count of the number of good items.

\Let me know if you have any questions.
0
 

Author Comment

by:nploving
ID: 2681629
Very good, but how do I count the part numbers that don't show up in this array.  Do I create a seperate array for parts not found.  I'm pretty lost here.  Do you know where I can find a bunch of examples of C++ array programs so that I can get a feel for what functions to use in various situations.  It would help me alot if you could take a look at what I've done.  I hope its not asking too much, but I'm in a pinch.  Thanks.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2682135
>> how do I count the part numbers that don't
>> show up in this array.  Do I create a seperate
>> array for parts not found.
I can't really say.  It depends on what the program needs to do--overall.

>> Do you know where I can find a bunch of
>> examples of C++ array programs
Almost no programs don't use arrays.  Arrays can be used in so so many this isn't likely to help you.  Better to develope what you need for this case.  I can probably help, but I don't know what you need to do.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ finding a sting in a char* string from a text file 3 130
C++ help/ Toy problem 19 49
C++ Code Issue 4 37
find Speed using GPS latitude & longitude 4 81
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question