Having Trouble With Program Organization/Structure

Hey guys! I am fairly new at C++, and seeing as I have followed several tutorials with basic syntax, structure, etc, I figured I would start up a small project on my own. Below what I have so far with my project.
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
  #include <iostream>
#include <string>

using namespace std;

std::string

int main()
{
	cout << " \n\t     ====|- Welcome to Project: Demacia! =|==== " << endl;
	cout << " \n\tBegin by searching any champion to view stats, lore, etc. : ";

	string pSearch;

	cin >> pSearch;
	if (pSearch == "Aatrox") { cout << " \n\t\tAatrox, the Darkin Blade. Primary Role: Fighter. " << endl; }
	else if (pSearch == "Ahri")  { cout << " \n\t\tAhri, The Nine Tailed Fox. Primary Role: Mage. " << endl; }
	else if (pSearch == "Akali")  { cout << " \n\t\tAkali, The Fist of Shadow. Primary Role: Assasin. " << endl; }
	else if (pSearch == "Alistar")  { cout << " \n\t\tAlistar, The Minotaur. Primary Role: Tank. " << endl; }
	else if (pSearch == "Amumu")  { cout << " \n\t\tAmumu, The Sad Mummy. Primary Role: Tank. " << endl; }
	else if (pSearch == "Anivia")  { cout << " \n\t\tAnivia, The Cryophoenix. Primary Role: Mage. " << endl; }
	else if (pSearch == "Annie")  { cout << " \n\t\tAnnie, The Dark Child. Primary Role: Mage. " << endl; }
	else if (pSearch == "Ashe")  { cout << " \n\t\tAshe, the Frost Archer. Primary Role: Marksman. " << endl; }
	else if (pSearch == "Azir")  { cout << " \n\t\tAzir, The Emporer of the   Sands. Primary Role: Mage. " << endl; }

	else cout << " \nCould not find a champion under that name. " << endl;

	return 0;
}


If any of you are familiar with the game League of Legends, I basically wanted to create a program that would allow you to search for a champion (only using a select few for this small project), it will tell you a brief description of the character, and then I want to basically loop the program after a search so you can choose if you want to search for another, or close, if that makes sense. As you can see, it's a mess.

I realize that I should have multiple functions for the input, probably a fuction that holds the descriptions for the champs, and so on, but I'm confused on how to go about structuring this. Would I need a function that can loop (ex. "Do you want to search for another champion, or close?". Any general tips or ideas would be greatly appreciated. Just want to make it as simple and easy to read as possible. Sorry if anything in this post is unclear.
I would make a champion class in your program with attributes available like the phrases you have included.

Something like this:

1
2
3
4
class Champion {
    string name;
    string description;
};


Although with such a small amount of information you could just make a struct as well.

Anyway, you could go through and add in all the Champion's descriptions and names one by one. It will probably take awhile.

Then you can keep the champions in something like a hash table for quick look up time(I have not played League of Legends, so I don't know how many of these champions there would be). You could organize the hash table on the first letters of their names.

Create a print function to print the champion's name and description.

That's all you wanted right. You said you're fairly new, do any of these things confuse you? I would be happy to help you build this thing.

P.S. This also gives you a good reason to learn more about hash tables, collisions, etc.
Last edited on
Hey thanks for the help. I am fairly new, I have heard of hash tables and classes, but I havent quite gotten to them yet. And I'd be more than happy to have you on board lol, but only if you want to :P
Sure man, shouldn't take too long and it would give me something to do. I can walk you through some of the code and let you try most of it yourself so you can do stuff like this in the future.

As for the hash table, that would only be needed if you had many champions, definitely in the thousands. Otherwise you can just use an array and create a search function to find any given one because the access to the champion you wanted would take little time if there were only a few.
Theres only about 100 champs in the game, it honestly wouldn't take too long, I have alot of free time these next few weeks as well haha. How do you wanna talk? We could message over skype or something (My mic is broken atm). Or over this website I guess, I'm new to forums as well. :/
Just send me a pm with an email to reach you at. Just click my user name and pm me.
Consider using set<> instead of a hash table because all you have to code is a less-than operator.

It would be really cool if you stored the info about the champions in a separate input file rather than hard coding them into the program. You could store the name on one line and the description on the next line. Then create an operator>> for the Champion class.
Topic archived. No new replies allowed.