Functions

Currently trying to learn about functions and parameters and I wrote this little program that asks for two numbers and adds them. However when I build it says "|13|error: 'sum' was not declared in this scope|", could someone please tell me where I've gone wrong? Thanks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  #include <iostream>

using namespace std;

double sumNumbers(double a, double b)
{
    double sum = a + b;
    return sum;
}

void printResult(double a, double b)
{
    cout << "You're answer is " << sum (a, b) << endl;
}

int main()
{
    cout << "Enter two numbers to be added" << endl;
    double a, b;
    cin >> a >> b;
    printResult (a, b);
    return 0;
}
Last edited on
line 13 - you're calling a function called sum which doesn't exist - did you mean to make that call sumNumbers?
All working now *had a blonde moment I think* thank you!!
Topic archived. No new replies allowed.