| I took the input and I believe I have implemented the majority of it. |
Excellent, I am pleased you are having a go !! So many young guys seem to ignore advice these days.
| I have not changed over std as I'm not comfortable with where and when to use with out using namespace. |
The only ones you really need are
std::cin and
std::cout You can change them in bulk by using find/replace in your editor. For anything else, you should be looking at the documentation anyway, so you will discover whether or not it is in std.
Avoid using
std::endl as it flushes the buffer every time, this could be a little inefficient. Just use '\n' instead:
std::cout << "How much cash do you have?\n";
There are times when
std::endl is OK, as is writing to log files, where one wants to ensure the latest data is being written, but not needed here.
int aisleOne();
These functions can be void, they don't return anything.
Change all your
float to
double.
double is the default, this is because the precision of
float is easily exceeded.
With line 27, you can make use of the
toupper() or
tolower() function to make this easier.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include <locale>
.
.
.
while(custChoiceAsUpperCase == 'Y')
{
// indentation makes code easier to read
totalCustomerPurchase = storeAisles();
customerPurchase += totalCustomerPurchase;
std::cout << "Woud you like to continue shopping? Y or N.\n";
std::cin >> custChoice;
char custChoiceAsUpperCase = std::toupper(custChoice);
}
|
Lines 95 to 107, these can all be
const.
95 96 97
|
const float totalCustomerPurchase;
const float bread = 1.0;
const float hotDogBuns = 1.0;
|
const is a really good feature of C++, it means the compiler can enforce the idea that you are not going to change it's value.
Lines 110 to 117 can be a void function, like the other menus.
With the
switch, consider changing
aisle to
char, then you can have a Quit case (
'Q')
Lines 123 to 128:
By putting the switch into a
while loop, we can handle errors with the
default: case of the switch.
Each case of the outer switch should call it's own function:
ProcessAisleOne(),
ProcessAisleTwo() ... say. The inner switched are OK, they only have one-liners.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
bool Quit = false;
while (!Quit) {
char aisle = 'z';
std::cout << "Which aisle would you like to go down? 1 , 2 , 3 , 4? Q to quit\n";
std::cin >> aisle;
switch(aisle) {
case: '1'
ProcessAisleOne();
break;
.
.
.
case: 'Q' // "Fall though", no break on purpose
case: 'q'
Quit = true;
break;
default: // catch errors with this
std::cout << "Wrong Choice, try again";
break;
} // end switch
} // end while
|
With
howMuchMoney you don't need parameters / arguments here. Remember to change the function declaration on line 14.
1 2
|
float howMuchMoney()
{
|
There we go, some more stuff to work on - you are doing well :+)