Another 'operator' error!

Hi, Forum! I need some help on my calculator once again. I'm working on my addition, but keep getting lots of errors.
Here's the header code for addition:
1
2
3
4
5
6
int addition(float a, float b)
{
    float result;
    result = a+b;
    return result;
}

Here's the main code for addition:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if (choice == 1)
        cout << "You chosen addition.";
        float a;
        float b;
        cout << "Enter a number you want to add.\n";
        cin >> a;
        cout << "Enter another number you want to add.\n";
        cin >> b;
        float ab;
        ab = addition(a,b);
        cout < "The answer is: " << ab << ".\n";
        cout << "1.Calculate again\n2.Exit the calculator program.\n";
         int choice1;
        if (choice1 == 1)
            goto calculate;
        else if (choice1 == 2)
            return 0;

The error this time is:
invalid operands of types 'const char[16]' and 'float' to binary 'operator<<'
I think it may be because floats can' be 'added' into strings. If I am correct, how do I turn a float into a string?
Line 11 you have a '<' symbol instead of the operator '<<'
cout < "The answer is: " << ab << ".\n";


By the way, the function should return a type float, not int.
1
2
3
4
float addition(float a, float b)
{
    return a+b;
}

Last edited on
Thanks, Chervil!
Topic archived. No new replies allowed.