First, please use code tags.
1 2 3 4 5 6 7 8 9 10
|
int Subtraction(int x, int y, int z)
{
int S;
S = x - y - z;
cout << "Please input 3 numbers to subtract" << endl;
cin >> x >> y >> z;
cout << "The three numbers subtracted were " << x << y << z;
cout << "The solution to the subtraction problem is " << S;
return S;
}
|
Easier to read, isn't it?
This function has some issues.
It is called with three values. That is ok.
You compute the value of S. That is ok, but we'll return to it.
You replace the values of x, y, z within the function. That affects only the following
cout << "The three numbers subtracted were " << x << y << z;
Statements are executed in order:
The value of bar is copied to foo before the value 42 is copied to bar.
You show the value of S (in itself ok), which has nothing to do with the values that you did show on the previous line. That will confuse the user.
You do return the value of S. That is ok. (However, your main() does nothing with the value.)
Why does the function show or ask anything? It has one task already: to compute. I/O with user is separate.
What does "number to subtract" mean? Subtract from what?
Is it intuitive that "subtraction of three numbers" means subtraction of two values from a third?
I get an error saying the identifiers are undefined. |
This is your code:
1 2 3 4 5 6 7 8 9 10
|
int main()
{
int submission;
cout << " Welcome to my math solver program! " << endl;
cout << " Please enter 1 for Addition, 2 for subtraction, 3 for Division, and 4 for multiplication " << endl;
cin >> submission;
if (submission == 1)
{
Addnumbers(x,y,z); // error: what is x? what is y? what is z?
|
You use x, y and z, but you have not declared, nor set their values.
How is the compiler supposed to know what to do?