Decimal Help

I am relatively new to C++ and I am building a calculator. I want to be able to add, subtract, multiply, and divide decimals but for some reason, I cannot. For example, if I did 1.23 + 4.56, I am given 5 instead of 5.79. Any help is appreciated!

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
#include <iostream>
#include "main.h"

int firstNumber()
{
    using namespace std;
    cout << "Welcome to my calculator! " << endl;// A short intro for the user
    cout << "What is your first number? ";// Prompts user to put their first number for the problem in
    double a = 0;//defines and resets variable that will be used to store the first number for the problem
    cin >> a;//Intakes the first number for the calculator
    return a;// Returns the number to the call in main.
}

int secondNumber()
{
    using namespace std;
    cout << "What is your second number? ";// Prompts user to put their second number for the problem in.
    double b = 0;//defines and resets variable that will be used to store the second number for the problem
    cin >> b;//Intakes the second number for the calculator
    return b;// Returns the number to the call in main.
}

int solving()
{
    using namespace std;
    double a = firstNumber();
    double b = secondNumber();
    cout << "What would you like to do with these numbers? (1 = +, 2 = -, 3 = *, 4 = /) ";// Prompts user to see what they will do with these two numbers
    double c = 0;//Defines and resets variable that will be used to translate the operator to an if statement.
    cin >> c;//Intakes number that will be translated into a operator.

    cout << " " << endl;// adding blankspace.

    if (c == 1) {//if statement that translates the number to a operator.
        cout << "Your answer is " << a + b;
    }
    if (c == 2) {//if statement that translates the number to a operator.
        cout << "Your answer is " << a - b;
    }
    if (c == 3) {//if statement that translates the number to a operator.
        cout << "Your answer is " << a * b;
    }
    if (c == 4) {//if statement that translates the number to a operator.
        cout << "Your answer is " << a / b;
    }
}

int main()
{
    solving();
    return 0;// the return
}
change
int firstNumber()
to
double firstNumber()

and so forth.

For why, look at http://www.cplusplus.com/doc/tutorial/variables/

Works great now! Thanks!
Topic archived. No new replies allowed.