I'm having a little trouble getting started on this HW assignment and would appreciate if anyone could clue me in where to begin logically.

The program takes names from the user as input up to 200 names or they stop and stores them in an array then uses two arrays to output to find out how many times a name is repeated and the number of occurrences.

Thanks in advance.

Recommended Answers

All 4 Replies

Do you know the difference between C style strings and STL string objects?

Do you know how to compare two C style strings? How about two STL string objects?

Do you know how to declare an array?

How about an array of ints? An arrary of C style strings? An array of STL strings? A vector of STL strings?

Will the names be a first name, a last name, a first and last name, a first and last name with middle initial, or some other concoction?

Do you know the difference between >> and getline() when it comes to entering strings? Do you know how to use getline() for both C style strings and STL string object?

Have you ever used a variable of type int to keep track of the number of times something gets done, or something appears, or whatever else you want to keep track of?

When you can answer those questions for either the C style string or STL string object options you can probably begin writing pseudocode for this project.

I think you can do this:

1. Declare arrays.
2. Loop that reads the names into array nr 1.
3. Loop that counts how many times each name appears in array nr1, then puts the number for each word into array nr 2. It also puts the name into array nr 3. You also check before putting number and name into 2 and 3 that the name is not there already(using another loop)
4. Print array 2 and 3

I think you can do this:

1. Declare arrays.
2. Loop that reads the names into array nr 1.
3. Loop that counts how many times each name appears in array nr1, then puts the number for each word into array nr 2. It also puts the name into array nr 3. You also check before putting number and name into 2 and 3 that the name is not there already(using another loop)
4. Print array 2 and 3

Thank you for your help, We actually just got introduced to arrays yesterday.

What would be the best way to count how many times something is used multiple times?

#include <iostream>
#include <string>
#include <math.h>

using namespace std;
char names [10][25];//declare 



int main()
{
int counter = 0; // set counter to zero

cout<<"Enter the Names:"<<endl;


//prompt user to input 10 names
for (int i = 0; i<9; i++)
{
	cout<<"Name"<<i+1<<": ";
	cin >> names[i];
	counter++;
}
//display 10 names
	for (int j=0;j<=9;j++)
	{
	    cout<<names[j]<<endl;   
	}

getchar();
 system("PAUSE");
}

You need atleast 2 loops:

Loop that goes through names
{
      Loop that checks the entire array to the name you have in the first loop. "if(names[outer] == names[inner])
      n++"{ }
}
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.