Having trouble calling two variables from method into main C++ -
i having trouble simple program. need call in method (getnumber) outside of main takes 2 numbers user , store numbers. 2 numbers used in calculation method (math) called main. getting uninitialized local variable 2 numbers calling in getnumber. user enter 2 numbers have them added , display result calling in methods.
#include <iostream> #include <string> using namespace std; int getnumber(int x, int y) { // here user prompted input 2 numbers cout << "please enter 2 values" << endl; cin >> x >> y; return x, y; } int math(int x , int y) // here calculations done { int result; result = x + y; return result; } int main() { int x; int y; int result; x = getnumber(x, y); // trying call in input method here result=math(x,y); // calling in claculation method cout << result; system("pause"); return 0; }
void getnumber(int &x, int &y) { cout << "please enter 2 values" << endl; cin >> x >> y; }
Comments
Post a Comment