5 Replies - 222 Views - Last Post: 05 February 2019 - 09:22 AM Rate Topic: -----

#1 allysa4   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-February 19

Can you please help me to code this using switch statement?

Posted 03 February 2019 - 09:13 PM

Create a horoscopes for each zodiac sign.
Display the horoscope for the zodiac sign entered.
Consider the following input:
Your zodiac sign:
Your horoscope:


If I input the other zodiac sign, it will input the same horoscope. How can I input the different horoscope in each zodiac? Here is my code:


using namespace std;
main() {
	
	int input;
	int zodiac;
	enum zodiac {aries, taurus, gemini, cancer, leo, virgo, libra, scorpio, sagittarius, capricorn, aquarius, pisces};
	cout<<"Your zodiac sign:";
	cin>>zodiac;
	
	switch(zodiac)
{
    case 0: zodiac = aries;
	cout<<"Your horoscope:";
	cout<<"You will have a lucky year"; break;
	case 1: zodiac = taurus; 
	cout<<"Your horoscope:";
	cout<<"You will find your perfect partner"; break;
	case 2: zodiac = gemini;
	cout<<"Your horoscope:";
	cout<<"Your lucky number is 5"; break;
	case 3: zodiac = cancer; 
	cout<<"Your horoscope:";
	cout<<"You will have a good health";break;
	case 4: zodiac = leo; 
	cout<<"Your horoscope:";
	cout<<"You will achieve your goals";break;
	case 5: zodiac = virgo;
	cout<<"Your horoscope:";
	cout<<"You will experience challenges this year";break;
	case 6: zodiac = libra; 
	cout<<"Your horoscope:";
	cout<<"Your ex partner will go back to you";break;
	case 7: zodiac = scorpio; 
	cout<<"Your horoscope:";
	cout<<"Your lucky color is red";break;
	case 8: zodiac = sagittarius;
	cout<<"Your horoscope:";
	cout<<"Your loved ones will confess to you";break;
	case 9: zodiac = capricorn;
	cout<<"Your horoscope:"; 
	cout<<"You will experience heartbreak";break;
	case 10: zodiac = aquarius; 
	cout<<"Your horoscope:";
	cout<<"You are far from danger";break;
	case 11: zodiac = pisces;
	cout<<"Your horoscope:";
	cout<<"You are getting married";break;
	
		default:
			cout<<"Program Terminated";	break;
		
	}
	
}

This post has been edited by no2pencil: 03 February 2019 - 09:25 PM
Reason for edit:: Corrected code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Can you please help me to code this using switch statement?

#2 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6730
  • View blog
  • Posts: 31,185
  • Joined: 10-May 07

Re: Can you please help me to code this using switch statement?

Posted 03 February 2019 - 09:27 PM

Why not print out the value inbetween the cin & the case statement?

	cin>>zodiac;
	cout<<zodiac;
	switch(zodiac)


You also don't have any break statements.

	switch(variable) {
		case value
		... process
		break;
		case value
		... process
		break;
	}


Was This Post Helpful? 0
  • +
  • -

#3 allysa4   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-February 19

Re: Can you please help me to code this using switch statement?

Posted 04 February 2019 - 08:56 PM

View Postno2pencil, on 03 February 2019 - 09:27 PM, said:

Why not print out the value inbetween the cin & the case statement?

	cin>>zodiac;
	cout<<zodiac;
	switch(zodiac)


You also don't have any break statements.

	switch(variable) {
		case value
		... process
		break;
		case value
		... process
		break;
	}



View Postallysa4, on 04 February 2019 - 08:56 PM, said:

View Postno2pencil, on 03 February 2019 - 09:27 PM, said:

Why not print out the value inbetween the cin & the case statement?

	cin>>zodiac;
	cout<<zodiac;
	switch(zodiac)


You also don't have any break statements.

	switch(variable) {
		case value
		... process
		break;
		case value
		... process
		break;
	}


Was This Post Helpful? 0
  • +
  • -

#4 allysa4   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-February 19

Re: Can you please help me to code this using switch statement?

Posted 04 February 2019 - 09:07 PM

Where will I put these :

cin>>zodiac;
cout<<zodiac;
switch(zodiac)

Pls help me, I don't know where will I input that code.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14845
  • View blog
  • Posts: 59,246
  • Joined: 12-June 08

Re: Can you please help me to code this using switch statement?

Posted 04 February 2019 - 09:19 PM

How about you try it out.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6730
  • View blog
  • Posts: 31,185
  • Joined: 10-May 07

Re: Can you please help me to code this using switch statement?

Posted 05 February 2019 - 09:22 AM

View Postallysa4, on 04 February 2019 - 11:07 PM, said:

Where will I put these :

cin>>zodiac;
cout<<zodiac;
switch(zodiac)

Pls help me, I don't know where will I input that code.

My suggestion was to add ONE line of code, TWO of those lines already exist.

& did you read the 2nd half of the post?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1