MaxDaniels wrote: |
---|
A break simply ends the current function prematurely, you are using breaks at the end of a function, so it's in effect not doing anything. |
A
break;
breaks out of a looping structure (switch, while, for, do-while). The OP has them at the end of each
case
, which is normal practice. To leave a function, one uses a
return
statement.
@imbritty
If it was me I wouldn't bother asking if they want a car wash as this seems to be the purpose of the program. So you could get rid of the do-while loop altogether. Same for asking if each user selection is OK, from a GUI point of view, I would find that a little irritating.
Line 106: An
else
cannot have a condition associated with it, it is meant to catch anything that doesn't match any of the
else if
, so it is useful for catching error conditions. Also you have a semicolon, which negates the compound statement on lines 107 to 110, and that should have attracted a compiler error. Which compiler are you using? Set the warning level to it's maximum.
Just like an
else if
chain should have an
else
to catch errors, so should a switch have a
default:
case - it will save you one day. Also search on this site for
TheIdeasMan bool controlled while loop for posts I have made about this.
It seems to me that you have too much code in
main()
, there is an unwritten rule that says that functions should be 40 LOC max, some people try for even less. Each case in the switch could call a function, say and displaying a menu could be in it's own function. With line 36, it might be better to show a menu, and have the user select from a choice B, P, D or 1, 2, 3 : with each option labelled as to what it does. At the moment what would happen if the user entered "Basic" ?
If using functions in your code, declare them before main, and define them in order after main.
Most importantly,
ALWAYS initialise your variable to something this is often the biggest cause of errors. Declare & initialise 1 variable per line, and only have 1 statement per line generally in your code.
Don't have
using namespace std;
, google why that is so - I have written a number of replies about that.
There you go, some stuff to think about :+)