my advice is for someone who's programmed a bit, maybe had 1-2 classes or learned on their own. if you're on week1 of your first class, this might be more confusing than helpful.
with respect to programming, the first red flag i see is that everything is inside main. i would isolate each "step" of the program into a separate function. you'll notice that each "step" does certain things:
1. prompt user for input
2. validate data
3. process data
which lays itself out nicely. you can also separate them into "tiers" or "layers" to abstract out cin/cout. if you wanted to reuse your program in the future without using the console (eg: you have a GUI with buttons/msgboxes/etc) it would be much easier. i'm more familiar with it in the OOP world, but i'm sure C has some way to do it (function pointers?).
Quote
Don't know (at the moment) how to restart something when you enter something that doesn't work - so I have to tell the user to restart
Putting stuff in multiple functions will help with this. it also makes it easier to manage recoveries when errors occur imo. the idea is that your program follows a certain "workflow", meaning that it has different states. when errors occur, you can keep it in the same state or change to a different state
As a practise for later, i'd suggest learning how to create log files. suppose you had a bug in your program and you want to figure it out. the only way is to keep staring at the code and running it through a debugger. also if you have separate functions, your log could include every input/output of every function you write, which greatly helps you narrow down where the problems are.
i also recommend creating your own library that you'll use in future projects. something like is a great candidate:
Quote
if (service == 'y' || service == 'Y')
You could create a library like so:
Code
public boolean cbool(string s) throws InvalidArgumentException{
if (s == 'y' || s == 'Y') return true;
if (s == 'n' || s == 'N') return false;
throw new InvalidArgumentException;
}
Obviously, look into other libraries first to avoid duplicate code.
This post was edited by carteblanche on Jun 25 2012 11:23pm