Why Does My Astrology Program End Without Outputting Anything?

  • Thread starter Thread starter sheepcountme
  • Start date Start date
  • Tags Tags
    Program
AI Thread Summary
The discussion revolves around a user struggling with a computer science assignment involving an astrology program. The user shares their code, which successfully compiles but fails to output results after prompting for the user's birth month and day. The main issue identified is that the program terminates too quickly for the user to see the output. A suggestion is made to run the program through a terminal or command prompt instead of double-clicking the executable. Additionally, it's recommended to add a line of code at the end to pause the program, allowing the user to read the output before it closes. The user confirms that this solution resolves their issue, enabling them to see the results of their program.
sheepcountme
Messages
80
Reaction score
1
I'm dead awful at computer science, but I have to take the class, and I'm struggling.

I wrote the following code for an astrology program (I'm sure it's completely awkward, but please bear with me, it at least made it through a successful build).

The problem is, it asks for the month and day, but then just ends and doesn't output anything. Any help you could give me to fix this would be very much appreciated. The book hasn't been much help at all.

Here's the code...

#include <iostream>
using namespace std;

int main()

{
int month, day;

cout << "Enter the month you were born, from 1 to 12. ";
cin >> month;

cout << "Enter the day you were born from 1 to 31. ";
cin >> day;

if ( (month==10&&day>25) || (month==11&&day<19) ) {
cout << "You are a Scorpio! Today you should eat lots of cookies! ";
} else if ( (month==11&&day>=19&&day<=24) ) {
cout << "You were born on the cusp of Scorpio and Sagittarius! ";
cout << "Today you should eat lots of cookies and pet a kitten! ";
} else if ( (month==11&&day>24) || (month==12&&day<19) ) {
cout << "You are a Sagittarius! Today you should pet a kitten! ";
} else if ( (month==12&&day>=19&&day<=24) ) {
cout << "You were born on the cusp of Sagittarius and Capricorn! ";
cout << "Today you should pet a kitten and beware of snails! ";
} else if ( (month==12&&day>24) || (month==1&&day<17) ) {
cout << "You are a Capricorn! Beware of snails today! ";
} else if ( (month==1&&day>=17&&day<=22) ) {
cout << "You were born on the cusp of Capricorn and Aquarius! ";
cout << "Beware of snails today and bring an umbrella! ";
} else if ( (month==1&&day>22) || (month==2&&day<16) ) {
cout << "You are an Aquarius! Bring an umbrella today! ";
} else if ( (month==2&&day>=16&&day<=21) ) {
cout << "You were born on the cusp of Aquarius and Pisces! ";
cout << "Bring an umbrella today and wear something pink! ";
} else if ( (month==2&&day>21) || (month==3&&day<18) ) {
cout << "You are a Pisces! Wear something pink today! ";
} else if ( (month==3&&day>=18&&day<=23) ) {
cout << "You were born on the cusp of Pisces and Aries! ";
cout << "Wear something pink today and beware of cheese! ";
} else if ( (month==3&&day>23) || (month==4&&day<17) ) {
cout << "You are an Aries! Beware of cheese today! ";
} else if ( (month==4&&day>=17&&day<=22) ) {
cout << "You were born on the cusp of Aries and Taurus! ";
cout << "Beware of cheese today and wear your pants backwards! ";
} else if ( (month==4&&day>22) || (month==5&&day<18) ) {
cout << "You are a Taurus! Wear your pants backwards today! ";
} else if ( (month==5&&day>=18&&day<=23) ) {
cout << "You were born on the cusp of Taurus and Gemini! ";
cout << "Wear your pants backwards today and speak in Italian! ";
} else if ( (month==5&&day>23) || (month==6&&day<19) ) {
cout << "You are a Gemini! Speak in Italian today! ";
} else if ( (month==6&&day>=19&&day<=24) ) {
cout << "You were born on the cusp of Gemini and Cancer! ";
cout << "Speak in Italian today and kiss a walrus! ";
} else if ( (month==6&&day>24) || (month==7&&day<20) ) {
cout << "You are a Cancer! Kiss a walrus today! ";
} else if ( (month==7&&day>=20&&day<=25) ) {
cout << "You were born on the cusp of Cancer and Leo! ";
cout << "You shold kiss a walrus today and wear a tuxedo! ";
} else if ( (month==7&&day>25) || (month==8&&day<20) ) {
cout << "You are a Leo! You should wear a tuxedo today! ";
} else if ( (month==8&&day>=20&&day<=25) ) {
cout << "You were born on the cusp of Leo and Virgo! ";
cout << "Today you should wear a tuxedo and call everyone 'Henry'! ";
} else if ( (month==8&&day>25) || (month==9&&day<20) ) {
cout << "You are a Virgo! Today you should call everyone 'Henry'! ";
} else if ( (month==9&&day>=20&&day<=25) ) {
cout << "You were born on the cusp of Virgo and Libra! ";
cout << "Today you should call everyone 'Henry' and do the moonwalk! ";
} else if ( (month==9&&day>25) || (month==10&&day<20) ) {
cout << "You are a Libra! Today you should do the moonwalk! ";
} else if ( (month==10&&day>=20&&day<=25) ) {
cout << "You were born on the cusp of Libra and Scorpio! ";
cout << "Today you should do the moonwalk and eat lots of cookies! ";

}


}
 
Technology news on Phys.org
It works for me.

My theory is you are compiling it and double clicking the binary produced. Have you ever tried opening the program via a terminal?

I'll just assume you are using windows and you should open the command prompt, navigate to the directory where you compiled it, and open it in the prompt.

If you are unfamiliar with command prompts, you can always add a little code bit at the end that can retrieve another keystroke so that you can have time to read what your program has printed out.
 
Great, thank you! Turns out it just wouldn't stay up long enough for me to see the result. Thanks a lot!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top