Gotcha. I'm getting an error here: if(!strcmp(search_name, aList[i].name))
Saying strcmp wasnt declared in the scope?
EDIT: sorry, fixed. Added #include <cstring>
So now I have an idea of what the histogram is like. However it is giving me weird errors and looks funky if I dont enter it in exactly like the name in the text file.
1 2 3 4 5 6 7 8 9 10 11 12 13
Please enter a name: wAlter
0:
0:
2130567168:
2686792:
4199691:
2346776:
4429:
-1:
0:
0:
0:
You should be starting to see why the menu can be left till later - just get the functions working.
Hint: To allow for WaLTeR you convert each character in the name to upper (or lower) case for both c-strings in the strcmp function. It's just a couple of extra lines in the find function.
Also, look at what the find function returns if no name is in the list. So ... in main
The -1 is a dummy index, it's common practice - good to know, so that if a name isn't found in the list the function returns an impossible array index ie -1.
So you can check if you get -1 in main and act accordingly. You can choose any impossible number you like to initialize the variable index. It could be 5001 as long it is outside the possible range of the array.
I'm giving you too much but I just updated to show you one way with changing case.
The warning is because int is being compared to what strlen function actually returns which is type size_t
You can ignore the warning if you like, I did because it makes the code look more complicated than it is. But now that you are an expert on this :) you can write
Select a menu option:
a - Print histogram for a name
b - Compare two names in a decade
c - Print top ten names for a decade
d - Quit (write anomalies)
Your selection: b
Enter a name: cAthY
Enter a name: toDD
Enter number corresponding to your decade:
1 - 1900-1909
2 - 1910-1919
3 - 1920-1929
4 - 1930-1939
5 - 1940-1949
6 - 1950-1959
7 - 1960-1969
8 - 1970-1979
9 - 1980-1989
10 - 1990-1999
11 - 2000-2005
Enter a decade: 8
Data for Cathy
215: *******************************************************************************
Data for Todd
43: ************************************************************************************************
The way I read this part you have to get two names and then compare the rankings of each for each decade. You're not required to compare the two names because they are already known to be different.
Why would you compare Walter with Walter?
So, if I'm right, you get the two names in the form of their index in the list, name1index and name2index and work from there.
aList[name1index].rank[0] etc is a critical part here for you to think about in comparing it to
aList[name2index].rank[0] etc
Also, read the findName function very carefully. It has the question built in to it, including the case conversion. It returns the index in the list which is all you need to get the name and full rankings for all decades. You can select which decade you want in the next step.
I kinda figured it would have to be something to do with that function. So something like int name1index and int name2index? Or would they be char? Do I need another for loop?
Or could I do a cin for aList[name1index].rank[0]?