Array Output Problems

Currently i'm working on a rudimentary Date Compatibly program. This section is to output couples based on how compatible they are. I was using the taken[pop][yes_no] array to prevent guys from being assigned multiple dates. However it's still assigning girls multiple dates.

Here's an example of an output:
1
2
3
4
5
6
7
8
9
10
11
12
Run Calculations? (y/n):y
Running...
Dylan and Sam
Ellie and Michael
Hannah and Tom
Zoni and Spencer
Zoni and Kai
Sofia and Logan
Anika and Liam
Jillain and David B
Taylor and George
Collien and George 


As you can see the program has assigned George two dates, whereas Kai and Spencer are doubling up. Anyone have any ideas why? Thanks.

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
71
72
73
cout<<"\nRun Calculations? (y/n):";
cin>>calculations;

if(calculations=='y')
  break;            }
            
cout<<"Running..."<<endl;


int poss=0;
int x;
const int pop = 9;
const int yes_no = 9;
int untaken[pop][yes_no]={{11,21,31,41,51,61,71,81,91},
                          {0,0,0,0,0,0,0,0,0}};
    for(x = 1;x <= RANK_E; x++)
    {
          for(int match=14; match>1; match--)
          {
                 for(int y= 1;y <= RANK_R;y++)
                 {poss=guys[x][y]+girls[y][x];
                 if(poss==match)
                 {int output;int f_output;string matched;string thegirl;
                              
                                              if(y*10==10)
                                              {matched = "Sam";output=true;untaken[y][1]++;}
                                              if(y*10==20)
                                              {matched = "Michael";output=true;untaken[y][1]++;}
                                              if(y*10==30)
                                              {matched = "Tom";output=true;untaken[y][1]++;}
                                              if(y*10==40)
                                              {matched = "Kai";output=true;untaken[y][1]++;}
                                              if(y*10==50)
                                              {matched = "Spencer";output=true;untaken[y][1]++;}
                                              if(y*10==60)
                                              {matched = "Logan";output=true;untaken[y][1]++;}
                                              if(y*10==70)
                                              {matched = "Liam";output=true;untaken[y][1]++;}
                                              if(y*10==80)
                                              {matched = "David";output=true;untaken[y][1]++;}
                                              if(y*10==90)
                                              {matched = "George";output=true;untaken[y][1]++;}
                                             
                                              
                                              if(x*10+1==11)
                                              {thegirl = "Dylan";f_output=true;}
                                              if(x*10+1==21)
                                              {thegirl = "Ellie";f_output=true;}
                                              if(x*10+1==31)
                                              {thegirl = "Hannah";f_output=true;}
                                              if(x*10+1==41)
                                              {thegirl = "Zani";f_output=true;}
                                              if(x*10+1==51)
                                              {thegirl = "Sofia";f_output=true;}
                                              if(x*10+1==61)
                                              {thegirl = "Anika";f_output=true;}
                                              if(x*10+1==71)
                                              {thegirl = "Jillian";f_output=true;}
                                              if(x*10+1==81)
                                              {thegirl = "Talor";f_output=true;}
                                              if(x*10+1==91)
                                              {thegirl = "Collien";f_output=true;}
                                              
                                                       if(output==true && f_output==true && untaken[y][1] <2)
                                                       {cout<<thegirl<<" and "<<matched<<endl;f_output=false;output=false;break;}
        }}}}

  
system("pause>nul");
    
return 0;

}
If you don't mind, I'll just go ahead and trim this, because I can't stand to look at it.
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
static const char *boy_names[]={"Sam","Michael","Tom","Kai","Spencer","Logan","Liam","David","George"};
static const char *girl_names[]={"Dylan","Ellie","Hannah","Zani","Sofia","Anika","Jillian","Talor","Collien"};

//...

for(x = 1;x <= RANK_E; x++){
	for (int match=14; match>1; match--){
		for (int y=1;y <= RANK_R;y++){
			poss=guys[x][y]+girls[y][x];
			if (poss==match){
				int output;
				int f_output;
				string matched;
				string thegirl;

				//This next bit is equivalent to your strings of ifs.
				if (y>=1 && y<=9){
					matched=boy_names[y-1];
					output=true;
					untaken[y][1]++;
				}
				if (x>=1 && x<=9){
					thegirl=girl_names[y-1];
					f_output=true;
				}
				
				if (output==true && f_output==true && untaken[y][1]<2){
					cout<<thegirl<<" and "<<matched<<endl;
					f_output=false;
					output=false;
					break;
				}
			}
		}
	}
}

Before I go on, I need to say a couple words on style. Don't do this:
int output;int f_output;string matched;string thegirl;
or this:
matched = "Liam";output=true;untaken[y][1]++;
It makes things too hard to see, and the harder it is to see code, the harder it is to see what it's doing.
Put no more than one statement per line. If necessary, less than that.

With that out of the way, on to the code itself.

1
2
3
4
const int pop = 9;
const int yes_no = 9;
int untaken[pop][yes_no]={{11,21,31,41,51,61,71,81,91},
                          {0,0,0,0,0,0,0,0,0}};
Do you realize that this creates a 9x9 array, and not a 9x2 array?

The main problem is that your array untaken only holds information about the untakenness of the guys.
Last edited on
Topic archived. No new replies allowed.