How do I turn my problem to have suboutine. Not so sure how to do it.

#include <iostream>
using namespace std;
 int main()
 {
    int x,y,z;
    cout << "Please enter first number: ";
    cin >> x;
    cout << "Please enter second number: ";
    cin >> y;
    z = x + y;
    cout << "Answer is \n" << z;
    return 0;
    }

For this small program, I would make the input operation a function.

You'll have to pass the x and y variables by reference is you want a single function call to get both.

Or you could have an input function that just gets one value and returns it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.