Help counting individual inputs in an array.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gator6688
    New Member
    • Sep 2007
    • 63

    Help counting individual inputs in an array.

    I wrote this program and so far so good but now I have to be able to count how many 1's, 2's, 3's, and 4's were entered. I am at a complete loss of where to begin. Could someone help me get started?

    Code:
    #include "stdafx.h"
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	const int People = 5;
    	int i, PeopleTypes[People], count=0;
    
    cout << "Enter 1 for Infant, 2 for Child, 3 for Teenager, or 4 for Adult\n";
    cout << "for each person that attended the school function.\n\n";
    
    	for(i=1; i<People; i++)
    	{
    		cout << "Person #" << i << ": ";
    		cin  >> PeopleTypes[i];
    	if (PeopleTypes[i]>4 || PeopleTypes[i]<1)
    	{
    	cout << "This is invalid input!\n\n";
    	
    	}
    	if (PeopleTypes[i]<0)
    		break;
    	}
    	
       
    	
    }
  • sanYAua007
    New Member
    • Oct 2007
    • 6

    #2
    Originally posted by gator6688
    I wrote this program and so far so good but now I have to be able to count how many 1's, 2's, 3's, and 4's were entered...
    This is one of the ways to solve your task:

    Code:
    #include "stdafx.h"
    using namespace std;
    //---------------------------------------------------------------------------
    
    <spoonfeeding code removed>
    Last edited by weaknessforcats; Oct 18 '07, 05:15 PM. Reason: Removed spoonfeed

    Comment

    Working...