I am so lost!

I am having trouble making the program loop the arrays but save the information to later be displayed, after the user decides to enter more teams. I used char i in the program but will it actually work in saving the information?

YES I KNOW THERE ARE LOTS OF ERRORS IN THIS CODE. ITS NO WHERE NEAR BEING DONE.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const int TEAM_NAME = 21;
const int CONT_NAME = 21;
const int PHONE_NUM = 13;
char team[TEAM_NAME];
void DisplayTeams( char[], int);
void TeamsByClassification(char[], char, char, int);
void DisplayContacts(char[], int);
bool Datachoice(char);

struct play
{
	string name[TEAM_NAME];
	char team_class;
	char divi_class;
	int divi_level;
	string contact[CONT_NAME];
	string contact_num[PHONE_NUM];
	double fee;

};


int main()
{
	char choice,
	     answer,
	     team_name,
	     contacts;
	bool more;
	play soccer;
	char i;
     i = 0;
	

	cout << "Please enter the information when prompted." << endl;

  do
  {

    switch (choice)
    {
        case 'Y':

    	cout << "Please enter Team name";
    	cin >> soccer.name[i];
    	cout << "Please enter the division class";
    	cin >> soccer.divi_class[i];
    	cout << "Please enter the division level";
    	cout << "Please enter the contact name.";
    	cout << "Please enter the contact's phone number.";
    	 i = i + 1;
    	 break;

    case 'N':

    	 DisplayTeams( team[TEAM_NAME], i);
    	 DisplayContacts(team[CONT_NAME], i);
    break;
    default:
    	cout << "Invalid entry.";
    }
	cout << "Do you want to register another team?" << endl;
	cout << "Please enter Y or N";
	choice = Datachoice(choice);
	cin >> choice;

  }while (more == true);

	return 0;
}
Well, you seem to be doing it right for the team name.

However, you've only declared divi_class to be a single character, so divi_class[i] is meaningless (and illegal). Did you want to store an array of those too?

Yes, you're accessing the elements of your name array sensibly, by using an array index. However, I'm not sure why you're using a char variable as an array index. Arrays are indexed by numbers, not letters, e.g. divi_class[0], divi_class[1] etc. As it happens, a char can implicitly be converted to an int, so it works, but it's not the normal way to do it. I don't see anywhere in your code where you're actually using it as a character - you only use it as an array index, so why not simply make it an int?


Last edited on
Let me just make sure I understand what your saying completely:

I should change
1
2
3
char team_class;
	char divi_class;
	int divi_level;

into strings and they should become arrays

char i should be changed to int

I should change
1
2
3
char team_class;
	char divi_class;
	int divi_level;

into strings

Well, that's up to you. Is a team class a single letter, or is it a string? Is a division class a single letter, or is it a string? Is a division level a number, or is it a string? You know what these things are, and you haven't told us.

and they should become arrays

If you want to store more than one of them, then, yes, you''ll need something that stores more than one value, and an array looks suitable.

Although unless there's a very good reason for using an array, you're much better off using a std::vector. Vectors do what arrays do, but they're safer, and easier to use. You'll be glad you made the effort to learn about them.

Once you've got that working, you might want to think about better ways to organize your data. If you have an array that stores one name per team, and another that stores a class per team, and another that stores a division level per team, and another, and another, it would be much more straightforward to have a structure that stores the information for one team, and then have a single array (or, better, a single vector) of structures.

EDIT:
char i should be changed to int

Well, that's what I would do. But then you may have had some particular reason for making it a char rather than an int in the first place.
Last edited on
Topic archived. No new replies allowed.