Join 136,837 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,576 people online right now. Registration is fast and FREE... Join Now!
Write a C program that prompt the user for his or her date of birth, before determining his or her Western Zodiac Sign. The program must remain in an infinite loop (prompt the user for his or her date of birth again, after each display of the previous result) until a unique key is pressed, indicating that the user wishes to exit the program. */
#include<stdio.h> void main() { int month; int day; int WZS(int day,int month); int e;
printf("Please enter your month of birth:\n"); scanf("%d",&month); printf("Please enter your day of birth:\n"); scanf("%d",&day);
do { if((day>=22)&&(day<=31)&&(month==12)) printf("Your western zodiac sign are Capricorn\n"); else if((day>=1)&&(day<=20)&&(month==1)) printf("Your western zodiac sign are Capricorn\n"); else if((day>=21)&&(day<=31)&&(month==1)) printf("Your western zodiac sign are Aquarius!\n"); else if((day>=1)&&(day<=21)&&(month==2)) printf("Your western zodiac sign are Aquarius\n"); else if((day>=22)&&(day<29)&&(month==2)) printf("Your western zodiac sign are Pisces\n"); else if((day>=1)&&(day<=21)&&(month==3)) printf("Your western zodiac sign are Pisces\n"); else if((day>=22)&&(day<=31)&&(month==3)) printf("Your western zodiac sign are Aries\n"); else if((day>=1)&&(day<=20)&&(month==4)) printf("Your western zodiac sign are Aries\n"); else if((day>=21)&&(day<=30)&&(month==4)) printf("Your western zodiac sign are Taurus\n"); else if((day>=1)&&(day<=21)&&(month==5)) printf("Your western zodiac sign are Taurus\n"); else if((day>=22)&&(day<=31)&&(month==5)) printf("Your western zodiac sign are Gemini\n"); else if((day>=1)&&(day<=21)&&(month==6)) printf("Your western zodiac sign are Gemini\n"); else if((day>=22)&&(day<=30)&&(month==6)) printf("Your western zodiac sign are Cancer\n"); else if((day>=1)&&(day<=22)&&(month==7)) printf("Your western zodiac sign are Cancer\n"); else if((day>=23)&&(day<=31)&&(month==7)) printf("Your western zodiac sign are Leo\n"); else if((day>=1)&&(day<=22)&&(month==8)) printf("Your western zodiac sign are Leo\n"); else if((day>=23)&&(day<=31)&&(month==8)) printf("Your western zodiac sign are Virgo\n"); else if((day>=1)&&(day<=22)&&(month==9)) printf("Your western zodiac sign are Virgo\n"); else if((day>=23)&&(day<=30)&&(month==9)) printf("Your western zodiac sign are Libra\n"); else if((day>=1)&&(day<=23)&&(month==10)) printf("Your western zodiac sign are Libra\n"); else if((day>=24)&&(day<=31)&&(month==10)) printf("Your western zodiac sign are Scorpio\n"); else if((day>=1)&&(day<=21)&&(month==11)) printf("Your western zodiac sign are Scorpio\n"); else if((day>=22)&&(day<=30)&&(month==11)) printf("Your western zodiac sign are Sagittarius\n"); else if((day>=1)&&(day<=21)&&(month==12)) printf("Your western zodiac sign are Sagittarius\n"); else printf("Wrong data!\n"); } while(WZS!=e);
ok here it is, first of all it should be int main() not void main(), secondly if you want the input to be part of the loop you have to put that inside the loop as i did, and lastly to stop the loop i used getchar() == 'e' inside the while() of the loop. That is all i changed.
CODE
#include <stdio.h>
int main() { int month; int day;
do { printf("Please enter your month of birth:\n"); scanf("%d",&month); printf("Please enter your day of birth:\n"); scanf("%d",&day);
if((day>=22)&&(day<=31)&&(month==12)) printf("Your western zodiac sign are Capricorn\n"); else if((day>=1)&&(day<=20)&&(month==1)) printf("Your western zodiac sign are Capricorn\n"); else if((day>=21)&&(day<=31)&&(month==1)) printf("Your western zodiac sign are Aquarius!\n"); else if((day>=1)&&(day<=21)&&(month==2)) printf("Your western zodiac sign are Aquarius\n"); else if((day>=22)&&(day<29)&&(month==2)) printf("Your western zodiac sign are Pisces\n"); else if((day>=1)&&(day<=21)&&(month==3)) printf("Your western zodiac sign are Pisces\n"); else if((day>=22)&&(day<=31)&&(month==3)) printf("Your western zodiac sign are Aries\n"); else if((day>=1)&&(day<=20)&&(month==4)) printf("Your western zodiac sign are Aries\n"); else if((day>=21)&&(day<=30)&&(month==4)) printf("Your western zodiac sign are Taurus\n"); else if((day>=1)&&(day<=21)&&(month==5)) printf("Your western zodiac sign are Taurus\n"); else if((day>=22)&&(day<=31)&&(month==5)) printf("Your western zodiac sign are Gemini\n"); else if((day>=1)&&(day<=21)&&(month==6)) printf("Your western zodiac sign are Gemini\n"); else if((day>=22)&&(day<=30)&&(month==6)) printf("Your western zodiac sign are Cancer\n"); else if((day>=1)&&(day<=22)&&(month==7)) printf("Your western zodiac sign are Cancer\n"); else if((day>=23)&&(day<=31)&&(month==7)) printf("Your western zodiac sign are Leo\n"); else if((day>=1)&&(day<=22)&&(month==8)) printf("Your western zodiac sign are Leo\n"); else if((day>=23)&&(day<=31)&&(month==8)) printf("Your western zodiac sign are Virgo\n"); else if((day>=1)&&(day<=22)&&(month==9)) printf("Your western zodiac sign are Virgo\n"); else if((day>=23)&&(day<=30)&&(month==9)) printf("Your western zodiac sign are Libra\n"); else if((day>=1)&&(day<=23)&&(month==10)) printf("Your western zodiac sign are Libra\n"); else if((day>=24)&&(day<=31)&&(month==10)) printf("Your western zodiac sign are Scorpio\n"); else if((day>=1)&&(day<=21)&&(month==11)) printf("Your western zodiac sign are Scorpio\n"); else if((day>=22)&&(day<=30)&&(month==11)) printf("Your western zodiac sign are Sagittarius\n"); else if((day>=1)&&(day<=21)&&(month==12)) printf("Your western zodiac sign are Sagittarius\n"); else printf("Wrong data!\n");
ok here it is, first of all it should be int main() not void main(), secondly if you want the input to be part of the loop you have to put that inside the loop as i did, and lastly to stop the loop i used getchar() == 'e' inside the while() of the loop. That is all i changed.
CODE
#include <stdio.h>
int main() { int month; int day;
do { printf("Please enter your month of birth:\n"); scanf("%d",&month); printf("Please enter your day of birth:\n"); scanf("%d",&day);
if((day>=22)&&(day<=31)&&(month==12)) printf("Your western zodiac sign are Capricorn\n"); else if((day>=1)&&(day<=20)&&(month==1)) printf("Your western zodiac sign are Capricorn\n"); else if((day>=21)&&(day<=31)&&(month==1)) printf("Your western zodiac sign are Aquarius!\n"); else if((day>=1)&&(day<=21)&&(month==2)) printf("Your western zodiac sign are Aquarius\n"); else if((day>=22)&&(day<29)&&(month==2)) printf("Your western zodiac sign are Pisces\n"); else if((day>=1)&&(day<=21)&&(month==3)) printf("Your western zodiac sign are Pisces\n"); else if((day>=22)&&(day<=31)&&(month==3)) printf("Your western zodiac sign are Aries\n"); else if((day>=1)&&(day<=20)&&(month==4)) printf("Your western zodiac sign are Aries\n"); else if((day>=21)&&(day<=30)&&(month==4)) printf("Your western zodiac sign are Taurus\n"); else if((day>=1)&&(day<=21)&&(month==5)) printf("Your western zodiac sign are Taurus\n"); else if((day>=22)&&(day<=31)&&(month==5)) printf("Your western zodiac sign are Gemini\n"); else if((day>=1)&&(day<=21)&&(month==6)) printf("Your western zodiac sign are Gemini\n"); else if((day>=22)&&(day<=30)&&(month==6)) printf("Your western zodiac sign are Cancer\n"); else if((day>=1)&&(day<=22)&&(month==7)) printf("Your western zodiac sign are Cancer\n"); else if((day>=23)&&(day<=31)&&(month==7)) printf("Your western zodiac sign are Leo\n"); else if((day>=1)&&(day<=22)&&(month==8)) printf("Your western zodiac sign are Leo\n"); else if((day>=23)&&(day<=31)&&(month==8)) printf("Your western zodiac sign are Virgo\n"); else if((day>=1)&&(day<=22)&&(month==9)) printf("Your western zodiac sign are Virgo\n"); else if((day>=23)&&(day<=30)&&(month==9)) printf("Your western zodiac sign are Libra\n"); else if((day>=1)&&(day<=23)&&(month==10)) printf("Your western zodiac sign are Libra\n"); else if((day>=24)&&(day<=31)&&(month==10)) printf("Your western zodiac sign are Scorpio\n"); else if((day>=1)&&(day<=21)&&(month==11)) printf("Your western zodiac sign are Scorpio\n"); else if((day>=22)&&(day<=30)&&(month==11)) printf("Your western zodiac sign are Sagittarius\n"); else if((day>=1)&&(day<=21)&&(month==12)) printf("Your western zodiac sign are Sagittarius\n"); else printf("Wrong data!\n");
after compiling when i press "e" .. it will come out somethings like this..
[please enter your month of birth: e (this is where i press e) please enter your day of birth: (can i make here straight away to be please enter another key to cotinue?) your western zodiac is leo. (here are very weird.after pressing e..it should not coming out right?)
please enter another key to continue]
anyone who can help? thanks ya..
This post has been edited by yuentong: 4 Oct, 2008 - 12:58 PM
it is going in order of operations. it will continue through the loop until it gets to the bottom where it checks the while().. try making it a while loop instead of a do{}while();... that might work, i'm not sure though
cpp
while(getchar() != 'e') { printf("Please enter your month of birth:\n"); scanf("%d",&month); printf("Please enter your day of birth:\n"); scanf("%d",&day);
if((day>=22)&&(day<=31)&&(month==12)) printf("Your western zodiac sign are Capricorn\n"); else if((day>=1)&&(day<=20)&&(month==1)) printf("Your western zodiac sign are Capricorn\n"); else if((day>=21)&&(day<=31)&&(month==1)) printf("Your western zodiac sign are Aquarius!\n"); else if((day>=1)&&(day<=21)&&(month==2)) printf("Your western zodiac sign are Aquarius\n"); else if((day>=22)&&(day<29)&&(month==2)) printf("Your western zodiac sign are Pisces\n"); else if((day>=1)&&(day<=21)&&(month==3)) printf("Your western zodiac sign are Pisces\n"); else if((day>=22)&&(day<=31)&&(month==3)) printf("Your western zodiac sign are Aries\n"); else if((day>=1)&&(day<=20)&&(month==4)) printf("Your western zodiac sign are Aries\n"); else if((day>=21)&&(day<=30)&&(month==4)) printf("Your western zodiac sign are Taurus\n"); else if((day>=1)&&(day<=21)&&(month==5)) printf("Your western zodiac sign are Taurus\n"); else if((day>=22)&&(day<=31)&&(month==5)) printf("Your western zodiac sign are Gemini\n"); else if((day>=1)&&(day<=21)&&(month==6)) printf("Your western zodiac sign are Gemini\n"); else if((day>=22)&&(day<=30)&&(month==6)) printf("Your western zodiac sign are Cancer\n"); else if((day>=1)&&(day<=22)&&(month==7)) printf("Your western zodiac sign are Cancer\n"); else if((day>=23)&&(day<=31)&&(month==7)) printf("Your western zodiac sign are Leo\n"); else if((day>=1)&&(day<=22)&&(month==8)) printf("Your western zodiac sign are Leo\n"); else if((day>=23)&&(day<=31)&&(month==8)) printf("Your western zodiac sign are Virgo\n"); else if((day>=1)&&(day<=22)&&(month==9)) printf("Your western zodiac sign are Virgo\n"); else if((day>=23)&&(day<=30)&&(month==9)) printf("Your western zodiac sign are Libra\n"); else if((day>=1)&&(day<=23)&&(month==10)) printf("Your western zodiac sign are Libra\n"); else if((day>=24)&&(day<=31)&&(month==10)) printf("Your western zodiac sign are Scorpio\n"); else if((day>=1)&&(day<=21)&&(month==11)) printf("Your western zodiac sign are Scorpio\n"); else if((day>=22)&&(day<=30)&&(month==11)) printf("Your western zodiac sign are Sagittarius\n"); else if((day>=1)&&(day<=21)&&(month==12)) printf("Your western zodiac sign are Sagittarius\n"); else printf("Wrong data!\n");
int main() { unsigned int month = 0, day = 0; for(;;) { printf("Please enter your month of birth: "); if (1 != scanf("%d", &month)) { // User did not enter a valid number, so exit break; }
printf("Please enter your day of birth: "); if (1 != scanf("%d", &day)) { // User did not enter a valid number, so exit break; }
if (month > 12 || month < 1) { printf("Invalid month\n"); continue; } if (day < 1 || day > 31) { printf("Invalid day\n"); continue; } if (day > days_per_month[month - 1]) { printf("Dumbass, %s only has, at the most, %d days!\nTry again!\n", months[month - 1], days_per_month[month - 1]); continue; }
You never asked the user to enter anything. More importantly, the getchar() is always going to read rest of the buffer input. You'll never actually get a chance to enter the key you want to read.
Put your logic in a function and call that. Here's one way to do your call loop:
cpp
#include <stdio.h> #include <stdlib.h>
void showSign(int month, int day) { // your code here }
int main() { int month, day; char input;
do { printf("Please enter your month of birth:\n"); scanf("%d",&month); printf("Please enter your day of birth:\n"); scanf("%d",&day); showSign(month, day);
// Note C doesn't read just a single character // you'll need to hit enter before it starts to look an things printf("Press any key to continue (e to exit)\n"); // note the space in front of the %c, it's important. scanf(" %c",&input); } while(input != 'e');