usingnamespace std;
#include <iostream>
int aa()
{
int a = 1;
return a;
}
int bb()
{
int b = 2;
return b;
}
void display(int a, int b)
{
intnew = a + b;
}
int main()
{
cout << display(a, b) << endl;
return 0;
}
Indeed, a and be are not declared in your main() function. Just because you have an a and a b declared elsewhere, does not mean they are visible to main(). What is it exactly that you are trying to achieve with this code?
usingnamespace std;
#include <iostream>
int aa()
{
int a = 1;
return a;
}
int bb()
{
int b = 2;
return b;
}
void display(int a, int b)
{
int c = a + b;
}
int main()
{
int a;
int b;
cout << display(a, b) << endl;
return 0;
}
Well for one thing in your main you never initialized a or b so your just passing in garbage. And another thing is that your display function isn't doing anything except assigning c a value. Not only that but display function is of type void thus it won't be able to return back the results. In order to get the results you want you'd have to change it from void to int. This is due to the fact that the results you are returning is of type int.
usingnamespace std;
#include <iostream>
int aa()
{
int a = 1;
return a;
}
int bb()
{
int b = 2;
return b;
}
int display(int a, int b)
{
int c = a + b;
return c;
}
int main()
{
int a;
int b;
cout << "Enter in two numbers: ";
cin >> a >> b;
cout << "Here are the results: ";
cout << display(a, b) << endl;
return 0;
}
thanks for the heads up with my void function, but it is not what I wanted to do.
In your example I have to assign new values to a and b, but in reality, I want to use the values assigned on int aa() and int bb().
usingnamespace std;
#include <iostream>
int aa()
{
int a = 1;
return a;
}
int bb()
{
int b = 2;
return b;
}
int display(int a, int b)
{
int c = a + b;
return c;
}
int main()
{
int a = aa();
int b = bb();
cout << "Here are the results: ";
cout << display(a, b) << endl;
return 0;
}