Help me with this program

Hi, i want put numbers and after sum. For example:

Input:

Numbers: 6 5 4

Exit:

Sum: 6 5 4 = 15

Look my code:

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
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

float add (float x, float &y){
    y += x;
    return y;
}

int main()
{
    float num;
    float num2 = 0;
    cout << "Numbers: ";
    cout << "Sum:  ";
    while(cin >> num && cin.peek() != '\n'){
            cout << num << " ";
            add(num, num2);
    }
    cout << num << " ";
    add(num, num2);
    cout << "= " << num2 << endl;
    return 0;
}

Works fine for me.
Topic archived. No new replies allowed.