Hi, I'm a newbie who just learn programming, my problem here is I just try to do a simple Addition program but the addition does not give a result but always give 0, I'm not sure which part I did wrong, can you please help me to debug the error since I not really understand about the function...The code below run on Borland C++, Thanks!
#include <iostream>
#include <conio>
int main(void)
{
int a,b,c;
void go(); //not sure whether this line correct?
cin>>a;
cin>>b;
go(); //not sure whether this line correct?
cout<<"The value c is \n"<<c;
getch();
return 0;
}
void go(void)
{
int a, b, c;
c=a+b;
}
but if no function, it will run well...
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <conio>
int main(void)
{
int a,b,c;
cin>>a;
cin>>b;
c=a+b;
cout<<"The value c is \n"<<c;
getch();
return 0;
}
On a technicality - line 8 isn't wrong - it is just unusual - you can declare a function (prototype) inside another function - however you can't define a function inside another function.
The real problem is that the variables a, b and c inside main function - are not the same as the variables inside the go function.
He needs to go and read up on functions, and variables and how to pass variables to functions, etc, etc..