Hello again all. I've been doing some more research into functions today and have come across a bit of a snag I haven't been able to just "lookup". Currently I have a very simple program that calculates the sum of two variables using two different functions:
#include <iostream>
using namespace std;
int addNum(int x, int y){
int sum = x + y;
return sum;
}
int main()
{
cout << addNum(4, 2);
return 0;
}
Instead of having x and y be fixed variables inside of the main function, I would like them to be based off of user input. For instance I could have something similar to below:
int main()
{
cout << addNum(x, y);
cout << "Pick your favorite number"; //this value would be stored in variable x
cin >> x;
cout << "Pick your second favorite number"; //this value would be stored in variable y
cin >> y;
return 0;
}
Unfortunately that doesn't seem to work. I would like to think I'm on the right track, but I haven't been able to find a good source for integrating user input into functions, if anyone has one or a few that I could reference and do some reading/research on that would be awesome. I could just be completely missing the point as well. Any help is greatly appreciated.