I am currently working on a small program as request by the teacher, having finished the task a week in advanced I was wondering how I could improve the coding to make it shorter and so on.
Anyways, the program requires that we enter the day and month of your birth and give you your 'astrological' sign and 'element' associated to it but also tell which other 'astrological' signs are 'compatible' with each other.
1 2 3 4 5 6 7
/* Belier */
if ((reponse_Mois == 3 && reponse_Jour >= 21) || (reponse_Mois == 4 && reponse_Jour <= 19))
{
cout << "Votre signe astrologique est le Belier\n";
cout << "Le signe de votre signe astrologique est le FEU\n";
cout << "Le Belier est compatible avec le Lion ainsi que le Sagittaire.\n";
}
Here is the original code as requested by the teacher, unfortunately, doing this 12 times is a pain in the ass.
So I was wondering if could I use a multi-dimensional array to separate 3 months in 4 categories (fire, air, water and earth) to make things easier and faster to write down.
I was wondering if it is possible to assign a name to each row ?
1 2 3 4 5 6 7 8
string signe [4][3] =
{
Fire : {"Belier","Lion","Sagittaire"},
Earth : {"Taureau","Vierge","Capricorne"},
Air : {"Gemeaux","Balance","Verseau"},
Water : {"Cancer", "Scorpion","Poisson"}
};
Would something such a thing be possible ? So instead of writing everything down, one by one 12 times, could I simply call the name of the row and tell here "these two others within this array are compatible with you" sort of thing ?
not like this.
You can do it one of 2 handy ways:
method 1 is simply to make the first column the label, so you now have a string[4][4] looking like {"Fire", "Belier", ... ...}
and method 2 is to use an enum:
enum elements
{
Fire,Earth,Air,Water, Max_elements
};
then you can do this
cout << signe[Fire][0];
If you want to write things like
"the fire signs are .... signe[...]... etc"
then the first method may be best.
If you want to see the word Fire in your code so you know what you are working with, the second method is best. You can use both methods if you need both capabilities.
there are other ways .. you can make a class that contains a string array and take an array of those, but that is probably overthinking this problem; that is suitable for larger and more complicated programs.