Void Function Blues...

I am making a simple calculator, and I can't get this function to work.

(Please disregard my stupid sentences)


Here it is:


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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>

//The PROBLEM - is void the right function at all?
void goodEndPrint(double dX, double dY, char chOperatorChoice)
{
    using namespace std;
     cout << dX << " " << chOperatorChoice << " " << dY << " = " << dX * dY <<
    ". Yay! Thankyou for using... me, the thinking man's stupid calculator!" << endl << endl;

}
int main()
{
    using namespace std;


//Firstly, an introduction to the calculator.
    cout << "Welcome to the friendly but very basic calculator!" << endl << endl <<
//The first number.
    "Please enter a number:                                   ";
    double dX; cin >> dX;

//The operator (I've only set it up for the 4 main operators)
    cout << endl << "Now, before you put your function in, I must remind you that I am very basic." <<
    endl << "Any function other than +, -, * (times) or / (divide) will cause me to EXPLODE." <<
    endl << "With that in mind," <<
    endl << "please enter the operation you would like to perform:    ";
    char chOperatorChoice;
    cin >> chOperatorChoice;

//The second number.
    cout << endl << "Enter another number:                                    ";
    double dY; cin >> dY;

    cout << endl << endl;

//The PROBLEM!
    if (chOperatorChoice == '+')
    void goodEndPrint(double dX, double dY, char chOperatorChoice);


//Or should I keep it like these ones (boring to write, but at least functionable)?
    else if (chOperatorChoice == '-')
    cout << dX << " " << chOperatorChoice << " " << dY <<
    " = " << dX - dY << ". Yay! Thankyou for using... me, the thinking man's stupid calculator!" << endl << endl;

    else if (chOperatorChoice == '*')
    cout << dX << " " << chOperatorChoice << " " << dY <<
    " = " << dX * dY << ". Yay! Thankyou for using... me, the thinking man's stupid calculator!" << endl << endl;

    else if (chOperatorChoice == '/')
    cout << dX << " " << chOperatorChoice << " " << dY <<
    " = " << dX / dY << ". Yay! Thankyou for using... me, the thinking man's stupid calculator!" << endl << endl;

// What happens if some smartalec messes the operation up.
    else cout << "VLADABOOM! See Told you. Humph. I'm only very basic, you know... {sniffle}" << endl << endl;

}




...But using the values dX as 1, dY as 1 and chOperatorChoice as +, here's what comes up:


Welcome to the friendly but very basic calculator!

Please enter a number:                                   1

Now, before you put your function in, I must remind you that I am very basic.
Any function other than +, -, * (times) or / (divide) will cause me to EXPLODE.
With that in mind,
please enter the operation you would like to perform:    +

Enter another number:                                    1



Process returned 0 (0x0)   execution time : 7.036 s
Press any key to continue.



Have I made a stupid mistake? Is void the wrong function altogether? Or is what I'm trying to do impossible without making it too hard?

I'm grateful for your help :)
Last edited on
Put return 0; on line 56.

EDIT:
You also need to put
using namespace std;
as Tamao said.
Last edited on
You should remove using namespace std; from the function and put it under #include <iostream> then you don't need to have it in every function

Last edited on
1
2
// This is how your call on line 38 should be:
goodEndPrint( dX, dY, chOperatorChoice);


Also, this looks like a work in progress. A better function name might be something like "add" and as such, you wouldn't need to pass it the operator choice. It's a little redundant as it stands (you test for '+' and then pass it to the function, as if the function doesn't know).
Last edited on
Take a look here: http://cplusplus.com/doc/tutorial/functions/

You've already defined your types in the goodEndPrint function so you don't specify them again when you call it. Call the function (line 38) with the simple function (arg1, arg2, etc.) format.

Also, your answer for '+' returns '*'. Oops.
That's solved it now! Thanks a lot, y'all. :D

Although @morecm I think you're right about the function names. I'm beginning to think this is a pretty redundant code already, actually...


!EDIT! @cnoeval OH DEAR ME. I wondered if anyone would notice that. :P I think I've got it as fixed as it can be now, anyhow.


Ah well. Onwards and upwards. Thanks again!
Last edited on
Topic archived. No new replies allowed.