1. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2003
Posts
11
Rep Power
0

#### Functions question

the following is a little program im working on to increase my knowledge of functions... it gives me 2 errors that i cant figure out...

on lines 47 and 61, compiler indicates there are too few arguments... what does this mean

here is the code

T.I.A.

Code:
```/*
Name: jCalc
Author: Jarrod Swart
Date: 22/09/03 19:05
Description: A simple 4 function calculator to improve my knowlege and understanding of functions.
*/

#include <iostream>
using namespace std;

// This begins the "graphical menu"
{
cout << "[][][][][][][][][][][][][][][][][][][]\n";
cout << "[]                                  []\n";
cout << "[] jCalc - 4 function calculator    []\n";
cout << "[]   ----------------------------   []\n";
cout << "[] 1. Add                           []\n";
cout << "[] 2. Subtract                      []\n";
cout << "[] 3. Multiply                      []\n";
cout << "[] 4. Divide                        []\n";
cout << "[] 5. About                         []\n";
cout << "[]   ----------------------------   []\n";
cout << "[] Input your choice, press enter   []\n";
cout << "[]                                  []\n";
cout << "[][][][][][][][][][][][][][][][][][][]\n";

}

{
cout << "jCalc was created by Jarrod Swart as a means to improve understanding of functions and general C++ knowledge.\n";
}

// a function to accept a value and go to the specified part of the program
// ie: if 5 is entered, it displays aboutText()
// currently only five is an option
{
{
}
}

int main()
{
menuSelection(); //allow user to input option
system("pause");
return 0;
}```
Last edited by azrael; September 22nd, 2003 at 06:41 PM.
2. menuSelection() takes an argument, you must supply it when you call it. Also, use of system calls should always be avoided. Use getchar() or something to keep the program from closing until you have viewed the results.
3. Actually, only one of your errors should be too few arguments. The other error should be that you neglected to return a value.

You declared the function menuSelection as taking one argument and returning an int. However, there is no return statement within the function. If you tell the compiler that you intend to return a value (by declaring the function's return type to be non-void), then you are required to include a return statement that returns that value. If you do not, then it is an error.

Now, when you call that function, you are not required to look at that return value, so that's not the error. However, when you call menuSelection, you failed to give it an argument. Again, since you told the compiler that the function takes one argument, you are required to provide it with one argument every time you call it. If you do not, then that is also an error.

Which accounts for the errors you got.
4. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2003
Posts
11
Rep Power
0
thanks for the help but i have no idea what im supposed to do in order to make the program function properly...i am an utter newbie
5. Originally posted by azrael
thanks for the help but i have no idea what im supposed to do in order to make the program function properly...i am an utter newbie
You declared the function, menuSelection, to expect one argument (int menuOption), so give it one!

You declared the function, menuSelection, to return an int value, so put a return statement in there!
6. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2003
Posts
11
Rep Power
0

Code:
```#include <iostream>
using namespace std;

// This begins the "graphical menu"
{
cout << "[][][][][][][][][][][][][][][][][][][]\n";
cout << "[]                                  []\n";
cout << "[] jCalc - 4 function calculator    []\n";
cout << "[]   ----------------------------   []\n";
cout << "[] 1. Add                           []\n";
cout << "[] 2. Subtract                      []\n";
cout << "[] 3. Multiply                      []\n";
cout << "[] 4. Divide                        []\n";
cout << "[] 5. About                         []\n";
cout << "[]   ----------------------------   []\n";
cout << "[] Input your choice, press enter   []\n";
cout << "[]                                  []\n";
cout << "[][][][][][][][][][][][][][][][][][][]\n";

}

{
cout << "jCalc was created by Jarrod Swart as a means to improve understanding of functions and general C++ knowledge.\n";
}

// a function to accept a value and go to the specified part of the program
// ie: if 5 is entered, it displays aboutText()
// currently only five is an option
{
{
return 0;
}
}

int main()
{
system("pause");
return 0;
}```
yet it gives me a parse error on line 59...

what should i do now
7. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2003
Posts
11
Rep Power
0
line 59 being

Code:
`menuSelection(int menuOption); //allow user to input option`
8. Originally posted by azrael

Code:
```#include <iostream>
using namespace std;

// This begins the "graphical menu"
{
cout << "[][][][][][][][][][][][][][][][][][][]\n";
cout << "[]                                  []\n";
cout << "[] jCalc - 4 function calculator    []\n";
cout << "[]   ----------------------------   []\n";
cout << "[] 1. Add                           []\n";
cout << "[] 2. Subtract                      []\n";
cout << "[] 3. Multiply                      []\n";
cout << "[] 4. Divide                        []\n";
cout << "[] 5. About                         []\n";
cout << "[]   ----------------------------   []\n";
cout << "[] Input your choice, press enter   []\n";
cout << "[]                                  []\n";
cout << "[][][][][][][][][][][][][][][][][][][]\n";

}

{
cout << "jCalc was created by Jarrod Swart as a means to improve understanding of functions and general C++ knowledge.\n";
}

// a function to accept a value and go to the specified part of the program
// ie: if 5 is entered, it displays aboutText()
// currently only five is an option
{
{
return 0;
}
}

int main()
{
system("pause");
return 0;
}```
yet it gives me a parse error on line 59...

what should i do now
I said give menuSelection an argument, not insert a declaration. What you wrote is not C. You need to pass the function either an integer literal or an int variable; e.g.: menuSelection(0); .

Also, when a function requires a return statement, ALL paths through that function must eventually end with a return statement. As you now have it, menuSelection will only return a value if the option is 5 and will otherwise not return a value. The compiler should have could that error as well.
Code:
```int menuSelection(int menuOption)
{
{
}
return 0;
}```
Now, what are you trying to do in that function? You are passing in a menuoption, but then you immediately replace it with user input. Why pass it in then? That doesn't make any sense. And what value are you returning? A function is supposed to perform a function. What function is this function supposed to perform?
9. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2003
Posts
2
Rep Power
0

#### to mitakeet

mitakeet
just curious as to why you said "use of system calls should always be avoided" ??...is it just from a portability issue or is there another reason.?? :confused:
10. One issue is certainly portablity. Another is security. It is fairly trivial to substitute another version of the same application on a different path and have that executed instead. This is not to say that I haven't done that myself from time to time, but since almost all OS's have been developed in C it doesn't make much sense to make system calls when the full OS functionality is available with just a little bit of research. In this particular case, the system call is being used to 'preserve' a DOS popup screen long enough to see what is on it. That could be done just as easily with a getchar() or something similiar. Don't use a screwdriver to do the job of a hammer!
11. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2003
Posts
2
Rep Power
0

#### mitakeet

point taken.......Never thought about security ....Still to new to C++ to have reached security issues, but I'll file this under make a "habit" not to use system calls-same catagory as goto.
Thanks..........:)
12. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2003
Posts
11
Rep Power
0
dwise... the following is unfinished and just a small part, the purpose of the function is to take a number 1-5 and then execute that particular function...