I have to make a program that enters either a 1, 2, 3, or 4 for 50 people attending a function. Then I have to be able to count how many of each 1's, 2's ,3's, and 4's there were. My 2 questions are:

1.) Would this program be better as a while loop so it is continous or a for loop?

2.) How could I start code to count each individual category?

#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;
	}
	
   
	
}

> 1.) Would this program be better as a while loop so it is continous or a for loop?
Flip a coin, make a choice.
I don't think there is a lot in either choice.
Both need to check the array limits (which suggests for) and the magic value from the user (which suggests while)

> 2.) How could I start code to count each individual category?
Two loops nested one inside the other
- for each category
- for each person

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.