Lebanese flag using switch

I am writing a program that draws the Lebanese flag in 2 sizes chosen by the user, but at execution, I am always getting the default case. Any idea why is this happening?
Thank you!

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
#include <iostream>
#include <iomanip>

using namespace std ;

void main () 
{
	int size , i , j , nbStars = 2 , nbSpaces , extLines , intLines , starsExt , starsInt , height ;
	char ans ;
	do
	{
		cout << "Enter 1 for small size, 2 for big size : " ;
		cin >> size ;
		switch ( size )
		{
		case ('1') :
			extLines = 2 ;
			intLines = 2 ;
			starsExt = 25 ;
			starsInt = 3 ;
			height = 5 ;
			nbSpaces = starsExt/2 ;
			break ;

		case ('2') :
			extLines = 4 ;
			intLines = 4 ;
			starsExt = 50 ;
			starsInt = 6 ;
			height = 10 ;
			nbSpaces = starsExt/2 ;
			break ;

		default :
			cout << "Wrong choice! " << endl ;
			extLines = 2 ;
			intLines = 2 ;
			starsExt = 25 ;
			starsInt = 3 ;
			height = 5 ;
			nbSpaces = starsExt/2 ;
		}

		//Les lignes exterieures du haut
		for ( i = 0 ; i < extLines ; i++ )
		{
			for ( j = 0 ; j < starsExt ; j++ )
				cout << '*' ;
			cout << endl ;
		}
		//La pyramide
		for ( i = 0 ; i < height ; i++ )
		{
			cout << setw (nbSpaces) ;
			for ( j = 0 ; j < nbStars ; j++ )
				cout << '*' ;
			cout << endl ;
			nbSpaces-- ;
			nbStars = nbStars+2 ;
		}
		//Les lignes interieures
		for ( i = 0 ; i < intLines ; i++ )
		{
			cout << setw (starsExt/2 - 1 ) ;
			for ( j = 0 ; j <= starsInt ; j++ )
				cout << '*' ;
			cout << endl ;
		}

		//Les lignes exterieures du bas
		for ( i = 0 ; i < extLines ; i++ )
		{
			for ( j = 0 ; j < starsExt ; j++ )
				cout << '*' ;
			cout << endl ;
		}


		nbStars = 2 ;
		do
		{
			cout << endl << "Continue (y/n) : " ;
			cin >> ans ;
			cout << endl << endl ;
		}
		while ( ans != 'y' && ans != 'n' ) ;
	}
	while ( ans == 'y' ) ;
}
Last edited on
size is an integer value but in switch-case you check it as a character.
'1' --> This is character
1 --> This is integer value
:)
wow, thank you for this fast reply :-)
Also...don't use void main()...use int main() instead.

http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.3
just checked it... thanks
Topic archived. No new replies allowed.