SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
More Flow Of Control
Exercise:
Programming Projects
Question:3 | ISBN:9780321531346 | Edition: 7

Question

Write an astrology program. The user types in a birthday, and the program responds with the sign and horoscope for that birthday. The month may be entered as a number from 1 to 12. Then enhance your program so that if the birthday is only one or two days away from an adjacent sign, the program announces that the birthday is on a “cusp” and also outputs the horoscope for that nearest adjacent sign. This program will have a long multiway branch. Make up a horoscope for each sign. Your program should include a loop that lets the user repeat this calculation until the user says she or he is done.


The horoscope signs and dates are:

Aries March 21–April 19

Taurus April 20–May 20

Gemini May 21–June 21

Cancer June 22–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

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer


//Header file section
#include<iostream>
using namespace std;
//Begin main function

void main()
{
  //Variable declartion
	int month, date;
	int startdate,startmonth,enddate,endmonth;
	char continues;
	do	
	{
       //Inputting day
	 cout<<" Enter the day of month for your birthday\n";
	 cin>>date;
	 //Inputting month
	 cout<<" Entre month of your birthday\n";
	 cin>>month;
	 if(month>12 || date>31)
	 	cout<<"Invalid input\n";
	 else
	{
	 startdate = 21;
      enddate = 19; 
	 startmonth = 3; 
	 endmonth = 4;
	if(( month == startmonth && date >= startdate) 
          ||(month == endmonth && date <= enddate))
	{
	  cout<<"Your Sign is :  aries \n";
	  if(date >= enddate-3)
	  cout<<" you are a cusp baby and with 
                           adjacent sign: Taurus \n";
	  else if(date <= startdate +3)
		cout<<" you are a cusp baby and with 
                              adjacent sign: Pieces \n";
	}
	 startdate = 20;
	 enddate = 20; 
	 startmonth = 4; 
	 endmonth = 5;
	 if(( month == startmonth && date>= startdate)
             ||(month ==endmonth && date <= enddate))
	{
	 cout<<"Your Sign is : Taurus\n";
	 if(date >= enddate - 3)
	 cout<<" you are a cusp baby and with adjacent 
                                   sign: Gemini \n";
	 else if(date <= startdate + 3)
		cout<<" you are a cusp baby and with 
                               adjacent sign: Aries \n";
    	}
	 startdate = 21;
      enddate = 21; 
	 startmonth = 5; 
	 endmonth = 6;
	 if(( month == startmonth && date >= startdate)
               ||(month == endmonth && date <= enddate))
	{
	  cout<<"Your Sign is : Gemini\n";
	  if(date >= enddate - 3)
	  cout<<"you are a cusp baby and with adjacent sign: 
                                               Cancer \n";
      else if(date <= startdate + 3)
	   cout<<"you are a cusp baby and with adjacent sign:
                                                Taurus \n";
	}
	  startdate = 22;
	  enddate = 22; 
	  startmonth = 6; 
	  endmonth = 7;
	  if(( month == startmonth && date >= startdate)
                 ||(month == endmonth && date <= enddate))
	  {
	 	cout<<"Your Sign is : Cancer\n";
	 	if(date >= enddate - 3)
			cout<<"you are a cusp baby and with adjacent 
                                              sign: Leo\n";
		else if(date <= startdate + 3)
		 cout<<"you are a cusp baby and with adjacent 
                                         sign: Gemini\n";
	  }
		startdate = 23;
		enddate = 22; 
		startmonth = 7; 
		endmonth = 8;
	if(( month == startmonth && date >= startdate) 
                  ||(month == endmonth && date <= enddate))
      {
	  cout<<"Your Sign is : Leo\n";
	  if(date >= enddate - 3)
		cout<<"you are a cusp baby and with adjacent
                                           sign: Virgo\n";
	 else if(date <= startdate + 3)
		cout<<"you are a cusp baby and with adjacent 
                                           sign: Cancer\n";
	 }
	  startdate = 23;
  	enddate = 22; 
	startmonth = 8; 
	endmonth = 9;
	if(( month == startmonth && date>= startdate) 
              ||(month == endmonth && date <= enddate))
	{
	 cout<<"Your Sign is : Virgo\n";
	 if(date >= enddate - 3)
	 cout<<"you are a cusp baby and with adjacent sign: 
                                              Libra\n";
	else if(date <= startdate + 3)
	 cout<<"you are a cusp baby and with adjacent sign:
                                                 Leo\n";
	}
	 startdate = 23;
	 enddate = 22; 
	 startmonth = 9; 
	 endmonth = 10;
	if(( month == startmonth && date>= startdate) 
                  ||(month ==endmonth && date <= enddate))
	{
	 cout<<"Your Sign is : Libra\n";
	 if(date >= enddate - 3)
	  cout<<"you are a cusp baby and with adjacent sign: 
                                                Scorpio\n";
	 else if(date <= startdate + 3)
		cout<<"you are a cusp baby and with adjacent 
                                          sign: Virgo\n";		}
	 startdate =23;
	 enddate = 21;
	 startmonth = 10; 
	 endmonth = 11;
	 if(( month== startmonth && date>= startdate) 
                 ||(month == endmonth && date <= enddate))
	 {
	   cout<<"Your Sign is :Scorpio\n";
	  if(date >= enddate - 3)
		cout<<"you are a cusp baby and with adjacent 
                                    sign: Sagitarius\n";
	 else if(date <= startdate + 3)
	  cout<<"you are a cusp baby and with adjacent sign: 
                                                Libra\n";
	}
	 startdate =22;
	 enddate = 21;
	 startmonth = 11; 
	 endmonth = 12;
	if(( month== startmonth && date>= startdate)
           ||(month == endmonth && date <= enddate))
	{
	 cout<<"Your Sign is :Sagittarius\n";
	 if(date >= enddate - 3)
	  cout<<"you are a cusp baby and with adjacent sign:
                                             Sagitarius\n";
	else if(date <= startdate + 3)
	 cout<<"you are a cusp baby and with adjacent sign: 
                                                Libra\n";
	}
	startdate = 22;
	enddate = 19; 
	startmonth = 12;
	endmonth = 1;
	if(( month== startmonth && date>= startdate) 
               ||(month ==endmonth && date <= enddate))
	{
      cout<<"Your Sign is : Capricorn\n";
	 if(date >= enddate - 3)
        cout<<"you are a cusp baby and with adjacent sign:
                                               Aquarius\n";
	 else if(date <= startdate +3)
	  cout<<"you are a cusp baby and with adjacent 
                                      sign:Sagittarius\n";
	}
	 startdate = 20;
	 enddate = 18;
	 startmonth = 1;
	 endmonth = 2;
 	if(( month== startmonth && date>= startdate) 
               ||(month ==endmonth && date <= enddate))
	{
	 cout<<"Your Sign is : Aquarius\n";
	  if(date>= enddate - 3)
		cout<<"you are a cusp baby and with adjacent
                                          sign: Pisces\n";
	 else if(date <= startdate + 3)
		cout<<"you are a cusp baby and with adjacent 
                                       sign: Capricorn\n";
	}
	 startdate = 19;
	 enddate = 20; 
	 startmonth = 2;
	 endmonth = 3;
	 if(( month == startmonth && date >= startdate) 
            ||(month == endmonth  && date <= enddate))
	{
		cout<<"Your Sign is : Pieces\n";
	   	if(date >= enddate - 3)
	      cout<<"you are a cusp baby and with adjacent 
                                            sign: Aries\n";
	   else if(date <= startdate + 3)
	     cout<<"you are a cusp baby and with adjacent 
                                       sign: Aquarius\n";
 	}
  }
  cout<<" To repeat calculations for different variables
                             then press 'y' or 'Y'\n";    
  cin>>continues;
 }while(continues=='y' || continues =='Y');
}//End main function

 

0 0

Discussions

Post the discussion to improve the above solution.