Trouble with a program

Started by
10 comments, last by AngleWyrm 13 years, 6 months ago
Hi everyone, I was wondering if someone could tell me why this won't compile. All it does is give me build errors and then doesn't build. Forgive me for how long the code is.

#include<iostream>using namespace std;int main(){	int day = 0;	int month = 0;	bool loop = true;	char ans;		do {		cout << "Welcome to the Horoscope program \n";		cout << "Please enter in the month you were born \n";		cin >> day;		cout << '\n';		cout << "Now enter the number of the month you were born in \n";		cin >> month;		switch (month){			case 1:				if(day >= 20 && day <= 31){                    cout << "You are an Aquarius \n";				    cout << "Tomorrow is going to be a great day!";				}                else if(day >= 1 && day <= 19)					cout << "You are a Capricorn \n";				    cout << "Fun things will happen to you!";					break;			case 2:				 if(day >= 1 && day <= 18){					 cout << "You are an Aquarius \n";					 cout << "Tomorrow is going to be a great day!";				 }				 				 else if(day >= 19 && day <= 28)					 cout << "You are a Pisces \n";				     cout << "You are going to have a great surprise soon!";					 break;			case 3:				if(day >= 1 && day <= 20){					cout << "You are a Pisces \n";				    cout << "You are going to have a great surprise soon!";				}								else if(day >= 21 && day <= 31)					cout << "You are an Aries \n";				    cout << "You will overcome a great obstacle!";					break;			case 4:				if(day >= 1 && day <= 19){					cout << "You are an Aries \n";				    cout << "You will overcome a great obstacle!";				}								else if( day >= 20 && day <= 30)					cout << "You are a Taurus \n";				    cout << "You will discover an awesome treasure!";					break;			case 5:				if(day >= 1 && day <= 20){					cout << "You are a Taurus \n";				    cout << "You will discover an awesome treasure!";				}				else if(day >= 21 && day <= 31)					cout << "You are a Gemini \n";				    cout << "You will find your true love soon!";					break;			case 6:				if(day >= 1 && day <= 21){					cout << "You are a Gemini \n";				    cout << "You will find your true love soon!";				}				else if(day >= 22 && day <= 30)					cout << "You are a Cancer \n";				    cout << "One day, you will be a great leader!";					break;			case 7:				if(day >= 1 && day <= 22){					cout << "You are a Cancer \n";				    cout << "One day, you will be a great leader!";				}				else if(day >= 23 && day <= 31)					cout << "You are a Leo \n";				    cout << "You will attract great people!";					break;			case 8:				if(day >= 1 && day <= 22){					cout << "You are a Leo \n";				    cout << "You will attract great people!";				}				else if(day >= 23 && day <= 31)					cout << "You are a Virgo \n";				    cout << "You will become a world class athlete!";					break;			case 9:				if(day >= 1 && day <= 22){					cout << "You are a Virgo \n";				    cout << "You will become a world class athlete!";				}				else if(day >= 23 && day <= 30)					cout << "You are a Libra \n";				    cout << "You will stop a terrible tragedy!";					break;			case 10:				if(day >= 1 && day <= 22){					cout << "You are a Libra \n";				    cout << "You will stop a terrible tragedy!";				}				else if(day >= 23 && day <= 31)					cout << "You are a Scorpio \n";				    cout << "Don't take the bus today!";					break;			case 11:				if(day >= 1 && day <= 21){					cout << "You are a Scorpio \n";				    cout << "Don't take the bus today!";				}				else if(day >= 22 && day <= 30)					cout << "You are a Sagittarius \n";					cout << "You are going to create the greatest invention ever!";					break;			case 12:				if(day >= 1 && day <= 21){					cout << "You are a Sagittarius \n";					cout << "You are going to create the greatest invention ever!";				}				else if(day >= 22 && day <= 31)					cout << "You are a Capricorn \n";				    cout << "Fun things will happen to you!";					break;			default: cout << "I don't understand";				}				cout << '\n';				cout << "Do you want to do another Horoscope?";				cout << '\n';				cout << "(y/n)";				cin >> ans;								}                while(loop == true && ans != 'n' && ans != 'N');				cout << '\n';				cout << "Goodbye!";				return 0;				}
Advertisement
Might be the compiler you are using, using VS2010 Pro it compiled and ran fine for me. Which IDE are you using to write your programs?

EDIT** Also source tags help for posting longer code.
Quote:Original post by wicked357
Might be the compiler you are using, using VS2010 Pro it compiled and ran fine for me. Which IDE are you using to write your programs?

EDIT** Also source tags help for posting longer code.


I am using Visual Studio 2010, I don't know why it's not compiling for me.
Quote:Original post by Blckknight118
All it does is give me build errors and then doesn't build.


Perhaps post the first few build errors?

Quote:Original post by BjsAust
Quote:Original post by Blckknight118
All it does is give me build errors and then doesn't build.


Perhaps post the first few build errors?


Never mind I got it to work, but I have another issue. I enter my birthday as May 23 and I get no fortune. Also, Some of theme are getting double fortunes which I also don't understand.

Never mind, I figured out what was wrong. It was glaringly obvious. I apologize if I wasted anyone's time.
Why not put a bunch of cout's in there to validate your values so you can see what the program is seeing?
Quote:Original post by BjsAust
Why not put a bunch of cout's in there to validate your values so you can see what the program is seeing?


I don't understand what you mean.....
Also, I'm still getting double prophecies and I don't know why.

Example: Enter in June 8 I get
You will find your true love!One day you will be a great leader!

I'm years past doing C but you'll get what I mean. For instance if you put:

do {		cout << "Welcome to the Horoscope program \n";		cout << "Please enter in the month you were born \n";		cin >> day;		cout << '\n';		cout << "Now enter the number of the month you were born in \n";		cin >> month;                cout << "Entered day: " + day + " and month: " + month + " \n";		switch (month){


Then you know exactly what is being evaluated by your switch statement, rather than just assuming you know. Do the same kind of stuff on the way through the code to work out the logic of what its actually doing, instead of what you think it should be doing.

You can wrap them in #debug type stuff, or just delete/comment them out once its working.
Quote:Original post by Blckknight118
Also, I'm still getting double prophecies and I don't know why.

Example: Enter in June 8 I get
You will find your true love!One day you will be a great leader!


You dont break inside your if statement, try using braces around your else logic to help see what the programs doing.

This topic is closed to new replies.

Advertisement