Hello lrdbash,
Thank you for using code tags.
Consider this as a start to your program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <string> // <--- Added.
using namespace std;
int main()
{
constexpr unsigned MAXROWS{ 5 }, MAXCOLS{ 2 };
string a[MAXROWS][MAXCOLS];
string b[MAXROWS][MAXCOLS]; // <--- Why is rows 6?
//int row, col;
cout << "Class 5A" << '\n';
for (unsigned row{}; row < MAXROWS; row++)
{
for (unsigned col{}; col < MAXCOLS; col++)
{
//cout << "\na[" << row << "][" << col << "]= "; // <--- May mean something to you, but looks bad to others. Useful for testing.
std::cout << "\n Enter name: ";
std::getline(std::cin, a[row][col++]);
std::cout << " Enter sex (F/M): ";
std::cin >> a[row][col];
std::cin.ignore();
}
}
|
First you need to get the input for "a" and "b", Choose better names than a single letter, working befoe you move on. The for loops that print the arrays are motly fine.
Notice how I used "MAXROWS" and "MAXCOLS" in the for loops. This not only makes the program easier to work with it also makes it easier to change the number of rows if you need to.
I would also recommend making sure the "sex" is a capital letter before you leave the inner for loop.
Unless you need the loop iterator outside the for loop, which you do not, it is better to define the iterator's type in the for statement and keep it local to the for loop. When the for loop is finished the variable is destroyed.
When you get to part "C" you need the for loops to check both arrays for "F" not just 1 or create a new array to hold only the female names.
If you are just printing the names a new array is not needed.
Later, when I have coded it, I will show you a way to speed up testing.
Andy