why my do-while loop are not working? it just exit the program after the zodiac sign showed

#include<iostream>
using namespace std;
int main()
{
Start:
int n,m;
cout<<"Zodiac Sign[1]"<<endl;
cout<<"Exit[2]"<<endl;
cin>>n;
do{
switch(n)
{
case 1:
int m,d;
cout<<"Please enter your birthday in numerical form:"<<endl;
cin>>m>>d;
if(m==3 && d>=21)
cout<<"Your zodiac sign is ARIES!"<<endl;
else if (m==4 && d<=19)
cout<<"Your zodiac sign is ARIES!"<<endl;

else if(m==4 && d>=20)
cout<<"Your zodiac sign is TAURUS!"<<endl;
else if(m==5 && d<=20)
cout<<"Your zodiac sign is TAURUS!"<<endl;

else if(m==5 && d>=21)
cout<<"Your zodiac sign is GEMINI!"<<endl;
else if(m==6 && d<=20)
cout<<"Your zodiac sign is GEMINI!"<<endl;

else if(m==6 && d>=21)
cout<<"Your zodiac sign in CANCER!"<<endl;
else if(m==7 && d<=22)
cout<<"Your zodiac sign in CANCER!"<<endl;

else if(m==7 && d>=23)
cout<<"Your zodiac sign is LEO!"<<endl;
else if(m==8 && d<=22)
cout<<"Your zodiac sign is LEO!"<<endl;

else if(m==8 && d>=23)
cout<<"Your zodiac sign is VIRGO!"<<endl;
else if(m==9 && d<=22)
cout<<"Your zodiac sign is VIRGO!"<<endl;

else if(m==9 && d>=23)
cout<<"Your zodiac sign is LIBRA!"<<endl;
else if(m==10 && d<=22)
cout<<"Your zodiac sign is LIBRA!"<<endl;

else if(m==10 && d>=23)
cout<<"Your zodiac sign is SCORPIO!"<<endl;
else if(m==11 && d<=21)
cout<<"Your zodiac sign is SCORPIO!"<<endl;

else if(m==11 && d>=22)
cout<<"Your zodiac sign is SAGITTARIUS!"<<endl;
else if(m==12 && d<=21)
cout<<"Your zodiac sign is SAGITTARIUS!"<<endl;

else if(m==12 && d>=22)
cout<<"Your zodiac sign is CAPRICORN!"<<endl;
else if(m==1 && d<=19)
cout<<"Your zodiac sign is CAPRICORN!"<<endl;

else if(m==1 && d>=20)
cout<<"Your zodiac sign is AQUARIUS!"<<endl;
else if(m==2 && d<=18)
cout<<"Your zodiac sign is AQUARIUS!"<<endl;

else if(m==2 && d>=19)
cout<<"Your zodiac sign is PISCES!"<<endl;
else if(m==3 && d<=20)
cout<<"Your zodiac sign is PISCES!"<<endl;
else;
break;

default:
cout<<"invalid output"<<endl;
break;

cout<<"Do you want to continue?[Y/N]"<<endl;
break;
}
}while(m<13);

return 0;
}
Last edited on
It looks like after taking in m and d as input, on line 17 you have an extra { which prevents it from compiling. After removing it, it compiles and runs just fine for me in DevC++. In the future you might want to start using indenting for nested statements to help troubleshoot and identify extra symbols. Good luck!
Last edited on
Thank you for helping my problem, that gives me a hard time looking for the error.
and one thing why my do-while loop were not working?
it just exit after the zodiac sign showed
Last edited on
I modified a little your code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include<iostream>
using namespace std;
int main()
{
Start:
int n,m;
cout<<"Zodiac Sign[1]"<<endl;
cout<<"Exit[2]"<<endl;
cin>>n;
do{

if(n==1){

  int m,d;
  cout<<"Please enter your birthday in numerical form:"<<endl;
  cin>>m>>d;

if(m==3 && d>=21)
cout<<"Your zodiac sign is ARIES!"<<endl;
else if ((m==4) && (d<=19))
cout<<"Your zodiac sign is ARIES!"<<endl;

else if(m==4 && d>=20)
cout<<"Your zodiac sign is TAURUS!"<<endl;
else if(m==5 && d<=20)
cout<<"Your zodiac sign is TAURUS!"<<endl;

else if(m==5 && d>=21)
cout<<"Your zodiac sign is GEMINI!"<<endl;
else if(m==6 && d<=20)
cout<<"Your zodiac sign is GEMINI!"<<endl;

else if(m==6 && d>=21)
cout<<"Your zodiac sign in CANCER!"<<endl;
else if(m==7 && d<=22)
cout<<"Your zodiac sign in CANCER!"<<endl;

else if(m==7 && d>=23)
cout<<"Your zodiac sign is LEO!"<<endl;
else if(m==8 && d<=22)
cout<<"Your zodiac sign is LEO!"<<endl;

else if(m==8 && d>=23)
cout<<"Your zodiac sign is VIRGO!"<<endl;
else if(m==9 && d<=22)
cout<<"Your zodiac sign is VIRGO!"<<endl;

else if(m==9 && d>=23)
cout<<"Your zodiac sign is LIBRA!"<<endl;
else if(m==10 && d<=22)
cout<<"Your zodiac sign is LIBRA!"<<endl;

else if(m==10 && d>=23)
cout<<"Your zodiac sign is SCORPIO!"<<endl;
else if(m==11 && d<=21)
cout<<"Your zodiac sign is SCORPIO!"<<endl;

else if(m==11 && d>=22)
cout<<"Your zodiac sign is SAGITTARIUS!"<<endl;
else if(m==12 && d<=21)
cout<<"Your zodiac sign is SAGITTARIUS!"<<endl;

else if(m==12 && d>=22)
cout<<"Your zodiac sign is CAPRICORN!"<<endl;
else if(m==1 && d<=19)
cout<<"Your zodiac sign is CAPRICORN!"<<endl;

else if(m==1 && d>=20)
cout<<"Your zodiac sign is AQUARIUS!"<<endl;
else if(m==2 && d<=18)
cout<<"Your zodiac sign is AQUARIUS!"<<endl;

else if(m==2 && d>=19)
cout<<"Your zodiac sign is PISCES!"<<endl;
else if(m==3 && d<=20)
cout<<"Your zodiac sign is PISCES!"<<endl;
else;
break;


cout<<"invalid output"<<endl;
break;
}
cout<<"Do you want to continue?[Y/N]"<<endl;
break;

}while(m<13);

return 0;
}


Now it works fine. I modified the switch structure with a if structure. You're using the switch structure to test 2 cases? I don't think it gaves you some eficiency. You may use switch for all another cases where you use else if (is just an advice if you want).
Topic archived. No new replies allowed.