[prog] C++

Sue Stones suzo at spin.net.au
Wed Jan 21 01:39:13 EST 2004


On Tue, 20 Jan 2004 11:49 pm, wolf wrote:
> Hi, I have a sample program from a book I've been working on and I have
> it to a point where it
> compiles without errors and runs. However, it fails to print the part
> about having to wait
> three hours for the next flight.  I was wondering if anyone might see
> the mistake I've made
> that is causing the program to skip over this part? Also, any
> suggestions for improvement
> are welcome as always : )
>
> Thanks : )

some comments about what the code is doing are included below.

> 	cout << "Please enter 1 for First Class or enter 2 for Economy: ";

Yoare asking the operator to answer either 1 or 2, so I presume that ishte 
input that you are giving the program.


> 		switch (Choice)
> 		{
> 			case 1:
> 				cout << "Your choice is 1.";
> 				break;
  If the choice was 1 print the above, then go to ****************
> 			case 2:
> 				cout << "Your choice is 2.";
> 				break;
 If the chooice is 2 print this statement , then go to ****************
> 			default:
> 				cout << "Next flight leaves in 3 hours." << endl;
   if the choice is *neither 1 or 2* then print this statement!
> 		}
	****************

Note that break causes control to leave the switch statement:
if I am right in thinking that you want to print the final staatement each 
time there is a correct response it should be moved *outside* the switch 
statement.

If this is not what you intended please indicate when you wish the default 
code to be run.

sue


More information about the Programming mailing list