Hi,
To call the function in main just do this:
this is a function declaration:
void EnterText();
It is a forward declaration and it tells the compiler that the definition of the function is later in the file. If yoou don't have the forward declaration then you need to have the definition of the function before main(). Forward declarations are better because you don't have to scroll through heaps of code before you get to main().
OK, we are on the right track with using functions to divide & conquer. There are 2 things to do now.
1. The processing of the menu option should be a function as well.
2. Change the do while to a while like this:
1 2 3 4 5 6
|
while ( ReturnMenu == 'Y') {
ProcessMenu()
};
cout << "\nGoodbye" << endl;
|
See how if you take the body of loop out and put it in function it makes it much easier to understand? If the body of the loop (the stuff between the braces) is more than 10 lines then it could be a candidate for doing this, although sometimes it is done when there are only a few lines.
When you come to extend this by writing the UseCalculator function (and the others) you will have these functions call other functions to do things.
I had another thought about the IsOperator function - we should always keep in mind that things will probably be extended or changed. So what if we had 10 operators? Instead of having a long test expression in the if statement, we should have a switch instead:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
bool IsOperator(char symbol){
switch (symbol);
{
case '+'
return true;
case '-'
return true;
case '*'
return true;
case '/'
return true;
default:
return false;
}
|
I haven't put break statements for each case like you would normally do because it will never get past each of the returns. break statements used like this prevent control "falling through" to the next case, which is not usually what you want.
So this is much easier to extend, and easier to read (better all round really).
I haven't seen this method of using cout before:
1 2 3 4 5 6 7
|
cout << "\n\t\t\t_______________________________\n"
" \t\t\t| What would you like to use? |\n" // Options the program offers
" \t\t\t|-----------------------------|\n"
" \t\t\t| (A) Guess the number |\n"
" \t\t\t| (B) Basic Calculator |\n"
" \t\t\t| (C) Print your text |\n"
" \t\t\t|_____________________________|" << endl;
|
I am more used to individual cout statementslike this:
1 2 3 4
|
cout << endl;
cout << "\t\t\t_______________________________" << endl;
cout << " \t\t\t| What would you like to use? |" << endl;
|
See how you go.
TheIdeasMan