Why Does My Astrology Program End Without Outputting Anything?

  • Thread starter Thread starter sheepcountme
  • Start date Start date
  • Tags Tags
    Program
Click For Summary
SUMMARY

The astrology program written in C++ fails to output results due to the absence of a pause before termination. The user is advised to run the program through a terminal to view the output, as double-clicking the binary file leads to immediate closure. Adding a line of code to wait for user input before exiting can also help in displaying the results. This solution effectively resolves the issue of the program ending without displaying any output.

PREREQUISITES
  • Basic understanding of C++ programming
  • Familiarity with command line interfaces (CLI)
  • Knowledge of input/output operations in C++
  • Experience with compiling and running C++ programs
NEXT STEPS
  • Learn how to implement a pause in C++ using system("pause") or cin.get()
  • Explore command line navigation and execution for Windows and Linux
  • Investigate debugging techniques in C++ to identify runtime issues
  • Study best practices for user input handling in C++ applications
USEFUL FOR

Beginner C++ programmers, students learning programming concepts, and anyone interested in improving their command line usage skills.

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;

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

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

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

Similar threads

  • · Replies 67 ·
3
Replies
67
Views
16K
  • · Replies 21 ·
Replies
21
Views
4K
Replies
16
Views
3K
  • · Replies 13 ·
Replies
13
Views
7K
  • · Replies 175 ·
6
Replies
175
Views
28K
  • · Replies 1 ·
Replies
1
Views
4K