Yes because I went over this with the lab aides that have taken the course and it was correct |
Maybe I should have been more blunt: Your code is a bit messy IMO. I think it is a poor show if your lab aides are saying it was correct.
Remember there is difference between code that works and code that is elegant. Maybe they don't have much time, and anything that works is OK. The other thing is interpretation, they may have said to use loops, but I would not have imagined something like what you have.
My main criticism is the repeated tests. Lines 26 to 37 gets the gender with an ugly test, and these tests are repeated throughout the code. If you didn't want to or not allowed to use a switch, you could use else if instead, and have each else if call a function to process that option. With loops, make use of a bool variable to control the loop. This avoids the repeated tests and makes the code much cleaner.
I am confused about this:
1 2 3
|
weightOk = (weight >= 110 && weight <= 185);
}while(weight >= 50 && weight <= 1400);
|
The condition for weightOk is different from that of the do loop - why not make use of the weightOk variable in the do loop condition? That way the loop could be a while loop. I always try to avoid do loops whenever I can.
As I said earlier these sorts of tests are ugly and not scalable:
}while(gender != 'x' && gender != 'X' && gender != 'F' && gender != 'f' && gender != 'm' && gender != 'M');
Also make use of the toupper function so you don't have to make 2 tests instead of one. Or in a switch:
1 2 3
|
case 'm':
case'M':
ProcessMale();
|
Even better is to have a menu with numerical options, that avoids the testing for upper / lower case altogether.
If I was a teacher I would allocate about 60% of the marks for well organised, elegant, easy to read code with functions. So if someone wrote a program that worked perfectly, but the code was an unintelligible mess to read - they would get a 40% score.
This sounds harsh, but compare it to communication skills - which should always be clear and simple
as possible. It is the same for programming.
I hope this helps - I don't know whether it is too late for this assignment - even so, good advice for the future I hope.