Logical error cannot be found

/*I am using Visual Studio 2019 for my c++ coding and i cannot find the logical error to my coding. When the user inputs their birthday, it should output their correlating astrological sign but when i put ANY birthday, it always outputs Aquarius. */

#include <iostream>
#include <string>


int main() {
std::string months[12] =
{ "January" , "Febuary" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" ,
"November" , "December" };

std::string astrological_month[12] =
{ "Aquarius", "Pisces" ,"Aries" ,"Taurus" ,"Gemini" ,"Cancer", "Leo" ,"Virgo" ,"Libra" ,"Scorpio" ,"Sagittarius", "Capricorn" };

int days[31] = { 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 };

std::string entry = "Please enter your birthdate to see what your astrological sign is: \n";
std::string user = "";

std::cout << entry;
std::cin >> user;

if (user == months[0] && days[19], days[20], days[21], days[22], days[23], days[24], days[25], days[26], days[27], days[28],
days[29], days[30] || user == months[1] && days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8],
days[9], days[10], days[11], days[12], days[13], days[14], days[15], days[16], days[17], days[18])
{
std::cout << astrological_month[0];
}

else if (user == months[1] && days[19], days[20], days[21], days[22], days[23], days[24], days[25], days[26], days[27] ||
user == months[2] && days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8],
days[9], days[10], days[11], days[12], days[13], days[14], days[15], days[16], days[17], days[18], days[19])
{
std::cout << astrological_month[1];
}

else if (user == months[2] && days[20], days[21], days[22], days[23], days[24], days[25], days[26], days[27], days[28],
days[29], days[30] || user == months[3] && days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8],
days[9], days[10], days[11], days[12], days[13], days[14], days[15], days[16], days[17], days[18], days[19])
{
std::cout << astrological_month[2];
}

else if (user == months[3] && days[20], days[21], days[22], days[23], days[24], days[25], days[26], days[27], days[28],
days[29] || user == months[4] && days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8],
days[9], days[10], days[11], days[12], days[13], days[14], days[15], days[16], days[17], days[18], days[19])
{
std::cout << astrological_month[3];
}

else if (user == months[4] && days[20], days[21], days[22], days[23], days[24], days[25], days[26], days[27], days[28],
days[29], days[30] || user == months[5] && days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8],
days[9], days[10], days[11], days[12], days[13], days[14], days[15], days[16], days[17], days[18], days[19])
{
std::cout << astrological_month[4];
}

else if (user == months[5] && days[20], days[21], days[22], days[23], days[24], days[25], days[26], days[27], days[28],
days[29] || user == months[6] && days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8],
days[9], days[10], days[11], days[12], days[13], days[14], days[15], days[16], days[17], days[18], days[19], days[20], days[21])
{
std::cout << astrological_month[5];
}

else if (user == months[6] && days[22], days[23], days[24], days[25], days[26], days[27], days[28],
days[29], days[30] || user == months[7] && days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8],
days[9], days[10], days[11], days[12], days[13], days[14], days[15], days[16], days[17], days[18], days[19], days[20], days[21])
{
std::cout << astrological_month[6];
}

else if (user == months[7] && days[22], days[23], days[24], days[25], days[26], days[27], days[28], days[29], days[30] ||
user == months[8] && days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8],
days[9], days[10], days[11], days[12], days[13], days[14], days[15], days[16], days[17], days[18], days[19], days[20], days[21])
{
std::cout << astrological_month[7];
}

else if (user == months[8] && days[22], days[23], days[24], days[25], days[26], days[27], days[28], days[29] || user == months[9] &&
days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8], days[9], days[10], days[11], days[12],
days[13], days[14], days[15], days[16], days[17], days[18], days[19], days[20], days[21])
{
std::cout << astrological_month[8];
}

else if (user == months[9] && days[22], days[23], days[24], days[25], days[26], days[27], days[28], days[29], days[30] ||
user == months[10] && days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8], days[9], days[10], days[11], days[12],
days[13], days[14], days[15], days[16], days[17], days[18], days[19], days[20], days[21])
{
std::cout << astrological_month[9];
}

else if (user == months[10] && days[22], days[23], days[24], days[25], days[26], days[27], days[28], days[29] || user == months[11] &&
days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8], days[9], days[10], days[11], days[12],
days[13], days[14], days[15], days[16], days[17], days[18], days[19], days[20], days[21])
{
std::cout << astrological_month[10];
}

else if (user == months[11] && days[22], days[23], days[24], days[25], days[26], days[27], days[28], days[29], days[30] || user ==
months[0] && days[0], days[1], days[2], days[3], days[4], days[5], days[6], days[7], days[8], days[9], days[10], days[11], days[12],
days[13], days[14], days[15], days[16], days[17], days[18])
{
std::cout << astrological_month[11];
}
else
{
std::cout << " \n That is not a valid date, silly gose.";

}
}
The code makes absolutely no sense. Literally everything after std::cin >> user; is completely wrong. It's unsalvageable, you have to start over.
* What input do you expect from the user?
* How do you expect to process it?
i'm fairly new to this so i'm bound to make multiple mistakes but i want the user to input their birthdate and the ifelse statement will determine whether if it falls within the parameters of the corresponding dates and months i put.
i want the user to input their birthdate
That's too vague. Here's just a small selection of ways I could enter my birthday into your program:
* 02/29
* 29/02
* Feb 29
* 29/2
* 2 29
* February 29th
* 29th of February
Last edited on
ok, a few more things.

c++ boolean expressions (eg x==y is a boolean expression: usually any comparison) must be *explicit*. That is, the computer does not get x == 3, 4,6 it only gets x==3 || x==4 || x==6 so your expressions are wrong.
second, they are also too complicated and large. use a range:
(user == months[9] && days[22], days[23], days[24], days[25], days[26], days[27], days[28], days[29], days[30] ||
should look like
(user == months[9] && user_day >=22 && user_day <= 30

also, there isnt any use for an array of days. and worse, your array of days is off by one: the first location in a c++ array is [0] so day[1] is 2 which is going to screw you up. That is probably also screwing up other things like the month, so keep an eye out. if you want to use 1 as the first index put a dummy first entry -- there are times when that makes sense, and making a calendar is one of them.

just use integers for the days, the user types in 10, its day 10, and you can use that in a comparison statement.

there are a lot of better ways to attack this but assuming you are just getting started here, go with the basic idea you had using these ideas and it should work fine.

so yes, you do need to scrap this, but you have a good idea of what you want to do and a fair first crack at it, you just messed up the syntax and array locations and all too much to fix it quickly, its easier to do over because of the issues because it is also still rather small so a redo will be easier.
Last edited on
Scrapping pretty much altogether might be a good move. But keep in mind any design work is an iterative process and there might be a few blind alleys. Knowing when to cut your losses when it's all getting too heavy is part of good design.

This is the astrology table - a highly scientific and totally infallible predictor of people's futures based on ... voodoo. But so be it.


Constellation 	English Name 	        Symbol 	Dates
Aries 	        The Ram 	                ♈ 	        Mar. 21–Apr. 19
Taurus 	        The Bull 	                ♉ 	        Apr. 20–May 20
Gemini 	        The Twins 	        ♊ 	        May 21–June 21
Cancer 	        The Crab 	                ♋ 	        June 22–July 22
Leo 	                The Lion 	                ♌ 	        July 23–Aug. 22
Virgo 	        The Virgin 	        ♍ 	        Aug. 23–Sept. 22
Libra 	        The Balance 	        ♎ 	        Sept. 23–Oct. 23
Scorpio   	        The Scorpion 	        ♏ 	        Oct. 24–Nov. 21
Sagittarius 	The Archer 	        ♐ 	        Nov. 22–Dec. 21
Capricorn 	        The Goat 	                ♑       	Dec. 22–Jan. 19
Aquarius 	        The Water Bearer 	♒ 	        Jan. 20–Feb. 18
Pisces 	        The Fishes 	        ♓ 	        Feb. 19–Mar. 20


Here's a few tips on how I would tackle it.

1. Months string array maybe including month[0] = 'dummy' as @jonnin recommends.
2. Days_in_month int array {1,31, 28, ... etc} for a leap year add 1 to month 2}
3. Create a month_number array 1 -> 365

And that's it because for each month/day combination you can get the day number and where it fits in the astrology time scale of start day number and end day number.

1
2
3
4
5
6
7
8
9
 const int NO_MONTHS = 12;
    const int NO_DAYS = 7;
    
    std::string month_names[NO_MONTHS] = 
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
    int days_per_month[NO_MONTHS] = 
{ 31 ,   28 ,   31 ,   30 ,   31 ,   30 ,   31 ,   31 ,   30 ,   31 ,   30 ,   31  };

    int cumulative_days[NO_MONTHS] = {0}; // get machine to fill this array 

Last edited on
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
#include <iostream>
#include <string>

struct Sign {
    std::string name;
    int end_day;
} Signs[] {
    {"Capricorn",    19}, // 12/22 -  1/19
    {"Aquarius",     18}, //  1/20 -  2/18
    {"Pisces",       20}, //  2/19 -  3/20
    {"Aries",        20}, //  3/21 -  4/20
    {"Taurus",       20}, //  4/21 -  5/20
    {"Gemini",       21}, //  5/21 -  6/21
    {"Cancer",       22}, //  6/22 -  7/22
    {"Leo",          22}, //  7/23 -  8/22
    {"Virgo",        21}, //  8/23 -  9/21
    {"Libra",        22}, //  9/22 - 10/22
    {"Scorpio",      21}, // 10/23 - 11/21
    {"Sagittarius",  21}  // 11/22 - 12/21
};

int main() {
    int m, d;
    std::cin >> m >> d; // should be sanity-checked
    int i = (m - (d <= Signs[m - 1].end_day)) % 12;
    std::cout << Signs[i].name << '\n';
}

By the look of it and on reflection leap years aren't significant.
Topic archived. No new replies allowed.