Help counting with an array.

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

    Help counting with an array.

    I am trying to figure out when I enter the data instead of asking for person #1: everytime I can get it to ask person #1: then on the next line person #2: and so on. Here is my code so far:

    Code:
    #include "stdafx.h"
    using namespace std;
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	const int People = 5;
    	int i, PeopleTypes[People];
    
    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=0; i<People; i++)
    	{
    		cout << "Person #1: ";
    		cin  >> PeopleTypes[i];
    	}
    
    	return 0;
    }
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Hmm, something like:
    Code:
    #include <iostream>
    using namespace std;
    
    int main(int argc, _TCHAR* argv[])
    {
    	const int People = 5;
    	int i, PeopleTypes[People];
    
    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=0; i<People; i++)
    	{
    		cout << "Person #" << i << ": "; 
    		cin  >> PeopleTypes[i];
    	}
    
    	return 0;
    }
    that?

    Comment

    Working...