Quick question!

Putting a second if statement within a switch statement :

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
   case 'm': cout << "Please enter a number between 1 and 20 to find the multiplication table of: "<<endl;
                                 cin >> number;
                                 if (number<=20)
                                 {
                                 system ("CLS");
                                 
                                 cout << "How many lines would you like the table to display? Enter a number between 1 and 15: "<<endl;
                                 cin >> lines;
                                 }
                                 else{
                                      cout<<"Please go back and enter a valid number!";
                                      }break;
                                 if(lines<=15)
                                 
                                 {
                                 system("CLS");
                                 
                                 
                                 for (count = 1; count <= lines ; count++)
                                 { 
                                     cout << "This is the multiplication table for the " << number << " times table";
                                     cout<<endl;                   
                                     cout << count << " * " << number<< " = " << count*number<<endl;
                                  
                                  }
                                  }
                                   else{cout<<"Please go back and enter a valid number!";}                    
                                 break;



The second else statement isn't displaying after you enter an invalid number, instead it is displaying at the same time as the first else statement! Quick help would be greatly appreciated !!
Well, I'm not sure if this will solve it, but you sure don't need a break in line 12. It is outside the else{} so it is executed independantly from whether number <= 20, or not.
Topic archived. No new replies allowed.