I need help on coding this program

Pages: 12

Create a program that will ask the user to input his/her birth month and birth date. The program should display the ZODIAC SIGN and its description based on his/her input month and date.

Use the table of Zodiac Sign below:
AQUARIUS - January 20 – February 18
PISCES - February 19 – March 20
ARIES - March 21 – April 19
TAURUS - April 20 – May 20
GEMINI May 21 – June 20
CANCER June 21 – July 22
LEO July 23 – August 22
VIRGO August 23 – September 22
LIBRA September 23 – October 22
SCORPIO October 23 – November 21
SAGUITTARIUS November 22 – December 21
CAPRICORN December 22 – January 19

Sample Output:
Enter your Birth month: 12
Enter your Birth date: 03
** Your Zodiac Sign is SAGUITTARIUS..

(And the description of SAGUITTARIUS)

and also the program should continue asking the user if he/she wants to test another input.

what codes should i use? i don't even know where to start..thanks guys!!
Rough idea
take input date and month.
1
2
cin>>date;
cin>>month;

1
2
3
4
5
6
7
if((month == 1 && date >= 20) || (month ==2 && date <= 18))
cout <<" Your Zodic Sign is SAGUITTARIUS..";
else if(condition for PISCES)
.
.
.
and so on;
That seems straightforward enough. What's the problem?
i'll try that..thanks but how about when the program should continue asking the user if he/she wants to test another input?
the problem is i can't start coz i don't know what to use..i'm thinking of else if and also do while..
Well then do it!
Have we got another troll? If so my second one today.

If not, then demonstrate you can do something, (anything) for your self.
Since the program may possibly have to run again aka LOOP then you'll need a looping mechanism. I'm sure you can figure out if you play around with it. That's the quickest way to learn.
guys, i'm having a problem

i already made the code but there is this problem

the output is:
enter birth month: 300
enter birth date: 31
invalid input

but when i tried this:
enter birth month: 12
enter birth date: 300
your zodiac sign is CAPRICORN

how do i fix this?

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
using namespace std;
int main()

{
    int month,date;
    cout<<" Enter your birth month:";
    cin>>month;
    cout<<" Enter your birth date:";
    cin>>date; 
    
    if (( month == 1 && date >= 20) || ( month == 2 && date <=18))
    {
         cout<<" Your zodiac sign is AQUARIUS\n";
         
    }
    else if (( month == 2 && date >= 19) || ( month == 3 && date <= 20))
    {
         cout<<" Your zodiac sign is PISCES\n";
    }
    else if (( month == 3 && date >= 21) || ( month == 4 && date <= 19))
    {
         cout<<" Your zodiac sign is ARIES\n";
    }
    else if (( month == 4 && date >= 20) || ( month == 5 && date <= 20))
    {
         cout<<" Your zodiac sign is TAURUS\n";
    }
    else if (( month == 5 && date >= 21 ) || ( month == 6 && date <= 20 ))
    {
         cout<<" Your zodiac sign is GEMINI\n";
    }
    else if (( month == 6 && date >= 21 ) || ( month == 7 && date <= 22 ))
    {
         cout<<" Your zodiac sign is CANCER\n";
    }
    else if (( month == 7 && date <= 23 ) || ( month == 8 && date <= 22))
    {
         cout<<" Your zodiac sign is LEO\n";
    }
    else if (( month == 8 && date >= 23 ) || ( month == 9 && date <= 22 ))
    {
         cout<<" Your zodiac sign is VIRGO\n";
    }
    else if (( month == 9 && date >= 23 ) || ( month == 10 && date <= 22))
    {
         cout<<" Your zodiac sign is LIBRA\n";
    }
    else if (( month == 10 && date >= 23 ) || ( month == 11 && date <= 21))
    {
         cout<<" Your zodiac sign is SCORPIO\n";
    }
    else if (( month == 11 && date >= 22 ) || ( month == 12 && date <= 21))
    {
         cout<<" Your zodiac sign is SAGUITTARIUS\n";
    }
    else if (( month == 12 && date >= 22 ) || ( month == 1 && date <= 19 ))
    {
         cout<<" Your zodiac sign is CAPRICORN\n";
    }
    else
    {
        cout<<" INVALID INPUT";
    }
         system("pause");
}
You need to add another condition

 
  else if (( month == 12 && date >= 22 && day <= 31) || ( month == 1 && date <= 19 ))


You'll have to do that on every month. Some will be <= 30, others <= 31 depending on the month. And Feb is <= 28.

Also none of them can be negative. Instead of declaring day and month as type int, use unsigned int.

i.e.
unsigned int month, day;
Last edited on
Oh, thanks and btw, how can i put a yes/no question?

example output:

Enter birth month: 12
Enter birth date: 12

Your zodiac sign is SAGUITTARIUS..

Do you want to continue? [Y/N]
y

then it will go back to enterering birth month and date..
Well what type is 'y' and 'n' ? That's the type you want to use. As for looping back up your program, use a looping mechanism.

http://www.cplusplus.com/doc/tutorial/control/
i don't know how to loop back to the enter birth month/date..and should i declare y and n as an integer? sorry kinda newb
Check the do-while tutorial in my link I just posted.

As for the y/n question – well you'll have a variable called something like answer and you will:

cin >> answer;

answer should either be 'y' or 'n' (or 'Y' or 'N').

You'll declare answer at the top. As for its type, I'll give you a multiple choice.
A) int
B) float
C) string
D) char

http://www.cplusplus.com/doc/tutorial/variables/
#include <iostream>
using namespace std;
int main(int argc, const char * argv[])
{
int date;
int month;
char ans;
cout<<"Enter the Date and Month:"<<endl;

while (!((ans=='n')&&(ans=='N'))){
cout<<"Enter the Date:"<<endl;
cin>>date;
cout<<"Enter the Month:"<<endl;
cin>>month;
if ((date>=20 && date<31 && month==1)||(date<=18 && date>=1 && month==2)){
cout<<"Your Zodiac Sign is AQUARIUS.."<<endl;
}
else if ((date>=19 && date<31 && month==2)||(date<=20 && date>=1 && month==3)) {
cout<<"Your Zodiac Sign is PISCES.."<<endl;
}
else if ((date>=21 && date<31 && month==3)||(date<=19 && date>=1 && month==4)) {
cout<<"Your Zodiac Sign is ARIES.."<<endl;
}
else if ((date>=20 && date<31 && month==4)||(date<=20 && date>=1 && month==5)) {
cout<<"Your Zodiac Sign is TAURUS.."<<endl;
}
else if ((date>=21 && date<31 && month==5)||(date<=20 && date>=1 && month==6)) {
cout<<"Your Zodiac Sign is GEMINI.."<<endl;
}
else if ((date>=21 && date<31 && month==6)||(date<=22 && date>=1 && month==7)) {
cout<<"Your Zodiac Sign is CANCER.."<<endl;
}
else if ((date>=23 && date<31 && month==7)||(date<=22 && date>=1 && month==8)) {
cout<<"Your Zodiac Sign is LEO.."<<endl;
}
else if ((date>=23 && date<31 && month==8)||(date<=22 && date>=1 && month==9)) {
cout<<"Your Zodiac Sign is VIRGO.."<<endl;
}
else if ((date>=23 && date<31 && month==9)||(date<=22 && date>=1 && month==10)) {
cout<<"Your Zodiac Sign is LIBRA.."<<endl;
}
else if ((date>=23 && date<31 && month==10)||(date<=21 && date>=1 && month==11)) {
cout<<"Your Zodiac Sign is SCORPIO.."<<endl;
}
else if ((date>=22 && date<31 && month==11)||(date<=21 && date>=1 && month==12)) {
cout<<"Your Zodiac Sign is SAGUITTARIUS.."<<endl;
}
else if ((date>=22 && date<31 && month==12)||(date<=19 && date>=1 && month==1)) {
cout<<"Your Zodiac Sign is CAPRICORN.."<<endl;
}
else {
cout<<"You Have entered wrong input"<<endl;
}

cout<<"do you ant to cntinue? Y/N"<<endl;
cin>>ans;
}return 0;

}
Last edited on
There is a problem with your code..when i input 'n' which means no..it still continues to entering the date/month..

EDIT: typo
Last edited on
Change
while (!((ans=='n')&&(ans=='N'))){
to
while (!((ans=='n') || (ans=='N'))){

The first one means it has to be n 'and' N. The second one means it has to be n 'or' N.

I would also either give ans some sort of starting value or change it to a do-while loop so that it works correctly the first time.
while (!((ans=='n')&&(ans=='N'))) will never false..
use
while (!((ans=='n') || (ans=='N')))
thanks guys!!!
I would like to add..

what if the person inputs neither y/n..so i need to display INVALID INPUT. Please try again.
Pages: 12