Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Have the user input their birthday month/day in the format (see examples): mm/dd

ID: 3787213 • Letter: H

Question

Have the user input their birthday month/day in the format (see examples): mm/dd. Then tell them their zodiac sign. The zodiac signs we will use for grading are listed here: http://www.psychicguild.com/horoscopes_explained.php You DO need to check that the month is valid. You may assume the day will be valid.

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

Sagittarius: November 22 - December 21

Capricorn: December 22 - January 19

Aquarius: January 20 - February 18

Pisces: February 19 - March 20

Example 1:

Enter the month/day when you were born:

1/2

Capricorn

Example 2:

Enter the month/day when you were born:

11/22

Sagittarius

Example 3:

Enter the month/day when you were born:

111/222

Invalid month

Explanation / Answer

Hi buddy, you didn't mention the language in which the program has to be written. I preferred C++. Comments are added for better understanding

#include <iostream>
using namespace std;

int main() {
   // your code goes here
   string db ;
   cin >> db;
   int date=0,i=0,month=0;
   //This loop traveres till '/' is encountered. It converts month part into number
   for( i=0;db[i]!='/';i++){
   //db[i]-48 converts character to a number. EG: '3' (character) will be converted to 3 (int).
   month = 10*month+(db[i]-48);
   }
   if(month>12){
   cout<< "Invalid month";
   return 0;
   }
   //This loop converts date String into date number
   for(int j=i+1;j<db.length();j++){
   date = 10*date+(db[j]-48);
   }
   string sign;
   if(month==3){
   if(date<=20){
   sign = "Pisces";
   }
   if(date>=21){
   sign = "Aries";
   }
   }
   if(month==4){
   if(date<=19){
   sign = "Aries";
   }
   if(date>=20){
   sign = "Taurus";
   }
   }
   if(month==5){
   if(date<=20){
   sign = "Taurus";
   }
   if(date>=21){
   sign = "Gemini";
   }
   }
   if(month==6){
   if(date<=20){
   sign = "Gemini";
   }
   if(date>=21){
   sign = "Cancer";
   }
   }
   if(month==7){
   if(date<=22){
   sign = "Cancer";
   }
   if(date>=23){
   sign = "Leo";
   }
   }
   if(month==8){
   if(date<=22){
   sign = "Leo";
   }
   if(date>=23){
   sign = "Virgo";
   }
   }
   if(month==9){
   if(date<=22){
   sign = "Virgo";
   }
   if(date>=23){
   sign = "Libra";
   }
   }
   if(month==10){
   if(date<=22){
   sign = "Libra";
   }
   if(date>=23){
   sign = "Scorpio";
   }
   }
   if(month==11){
   if(date<=21){
   sign = "Scorpio";
   }
   if(date>=22){
   sign = "Sagittarius";
   }
   }
   if(month==12){
   if(date<=21){
   sign = "Sagittarius";
   }
   if(date>=22){
   sign = "Capricorn";
   }
   }
   if(month==1){
   if(date<=19){
   sign = "Capricorn";
   }
   if(date>=20){
   sign = "Aquarius";
   }
   }
   if(month==2){
   if(date<=18){
   sign = "Aquarius";
   }
   if(date>=19){
   sign = "Pisces";
   }
   }
  
   cout << sign;
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote