Two switch statements, skipping the second one.

I have two switch statements in my program. If a user enters a 10 through 19 and the program enters the "Case 1" in the first switch statement, how can I program it that it should then skip the second switch statement?

The "Break;" at the end of case 1 breaks out of the first switch, then goes right into the second one. Any ideas?


switch (first_digit)

{
case 1:
if (double_digit == 10) cout << "ten.";
if (double_digit == 11) cout << "eleven.";
if (double_digit == 12) cout << "twelve.";
if (double_digit == 13) cout << "thirteen.";
if (double_digit == 14) cout << "fourteen.";
if (double_digit == 15) cout << "fifteen.";
if (double_digit == 16) cout << "sixteen.";
if (double_digit == 17) cout << "seventeen.";
if (double_digit == 18) cout << "eighteen.";
if (double_digit == 19) cout << "nineteen.";
break;
Do you have some loops?
Yes, I have a FOR loop in there for it to run up to 10 times:

#include <iostream>
using namespace std;

int main()

{
int i, num, double_digit, first_digit, second_digit;
char yes_no;
for (i=0; i<10;)

{
cout << "Enter a two-digit number: ";
cin >> double_digit;
cout << endl;
cout << "You entered the number ";

first_digit = double_digit / 10;
second_digit = double_digit % 10;

switch (first_digit)

{
case 1:
if (double_digit == 10) cout << "ten.";
if (double_digit == 11) cout << "eleven.";
if (double_digit == 12) cout << "twelve.";
if (double_digit == 13) cout << "thirteen.";
if (double_digit == 14) cout << "fourteen.";
if (double_digit == 15) cout << "fifteen.";
if (double_digit == 16) cout << "sixteen.";
if (double_digit == 17) cout << "seventeen.";
if (double_digit == 18) cout << "eighteen.";
if (double_digit == 19) cout << "nineteen.";
break;

case 2:
cout << "twenty ";
break;

case 3:
cout << "thirty ";
break;

case 4:
cout << "forty ";
break;

case 5:
cout << "fifty ";
break;

case 6:
cout << "sixty ";
break;

case 7:
cout << "seventy ";
break;

case 8:
cout << "eighty ";
break;

case 9:
cout << "ninety ";
break;
}

switch (second_digit)

{
case 1:
cout << "one."; cout << endl;
break;

case 2:
cout << "two."; cout << endl;
break;

case 3:
cout << "three."; cout << endl;
break;

case 4:
cout << "four."; cout << endl;
break;

case 5:
cout << "five."; cout << endl;
break;

case 6:
cout << "six."; cout << endl;
break;

case 7:
cout << "seven."; cout << endl;
break;

case 8:
cout << "eight."; cout << endl;
break;

case 9:
cout << "nine."; cout << endl;
break;
}
cout << endl;
cout << "Do you want to enter another number? (Y/N)";
cout << endl;
cin >> yes_no;

if (yes_no == 'Y') i = i + 1;
else (i = i + 10);
}

cin >> num;
return 0;

}

Now I understand the problem.
You need to make the program know that you don't want the second switch to be executed
eg:
1
2
3
4
5
6
7
8
9
10
11
switch (first_digit)
{
    //...
}

//execute second switch only if fisrt_digit is not equal to 1
if ( first_digit != 1 )
     switch ( second_digit )
     {
           //...
     }



And please use [code][/code] tags
That explains that, thanks much!
Topic archived. No new replies allowed.