[prog] C++

Sue Stones suzo at spin.net.au
Wed Jan 21 02:04:59 EST 2004


On Wed, 21 Jan 2004 12:39 am, Namik Dala wrote:
> On Tue, Jan 20, 2004 at 07:49:10AM -0500, wolf wrote:
> > 	cin    >> Choice;
>
> You're reading in Choice,
>
> > 	cout << endl;
> >
> > 	if (Choice = 1)
>
> And here you set Choice to 1. It doesn't matter what you've
> entered before. Maybe you want to remove the if-clause.

Good point,  I don't know what you inteneded by this statement, but it is hard 
to see anything that might have called for an if statement in this  place.

>
> > 		switch (Choice)
> >
> > 		{
> >
> > 			case 1:
> >
> > 				cout << "Your choice is 1.";
> >
> > 				break;
> >
> > 			case 2:
> >
> > 				cout << "Your choice is 2.";
> >
> > 				break;
> >
> > 			default:
> >
> > 				cout << "Next flight leaves in 3 hours." <<
> > 				endl;
> >
> > 		}
>
> You're setting Choice to 1, therefore only case 1 is matching.
> The default statement executes only if Choice is not 1 or 2,
> because of the break statements in the cases.
>
> If you want to execute the default in any case, remove the
> break statements.

Sory to contradict you Namik but removing the break statements will result 
inthe following if Choice is 1:

Your choice is 1.Your choice is 2.Next flight leaves in 3 hours.

I don't think this was intended.


wolf,  you may like to add some nicities to your output, like spaces at the 
end of the sentences, and newlines at the end of each "customers" info.  It 
will make it much easier to read when you are testing with a sample size of 
more than one.

sue


More information about the Programming mailing list