Hi,
Just a small tip to help you avoid this problem:
Either configure your IDE (if using one) to automatically do closing braces, parentheses, brackets etc, or;
Get into the habit of typing the opening brace, immediately followed by the closing one, then go back and fill in what goes in between the two.
Try to avoid mixing different styles of indenting and brace placement, for example you have this:
118 119 120 121 122 123
|
if (nMonth == '03'){
if (nDay >= 21)
{
cout << "You are an Aries."
<< endl;
}
|
To be consistent, one might have this:
118 119 120 121 122 123 124 125 126 127 128 129 130
|
if (nMonth == '03')
{
if (nDay >= 21)
{
cout << "You are an Aries."
<< endl;
}
// other nested if statements
// other closing brace at the end of first if statement, in the same
// column as the one on line 119
}
|
Choose which style you like, and stick to it. The main thing is to ensure that it is visually obvious whether it is right or wrong.
Also, about the logic:
But the program is working now, thank you! |
Unfortunately that doesn't always mean it is as good as it could be. Did you test values for each month?
You have a lot of tests for which month it is, but there are a lot that are nested inside an existing test for a month. For example the tests in lines 29 - 94 will always be false.
If I was doing it, there would be some error checking on the values entered for month and day - months 1 to 12 , and days in the correct range (no Feb 30 etc).
Then the logic is simple: use a
switch
statement with a
default
case to determine the
month
, then an
if
else
on the value of
day
to determine the star sign. You could use the ternary
? :
operator to do that on one line of code.
Hope all is well, and seasons greetings o<:+)