mo elsaid · January 11, 2015 im beginner in c++ but im trying to run this program, but it doesnt work  #include using namespace std;void numberA(){int a;cin >> a;}void numberB(){    int b;    cin >>b;}void sum(){    int numberA(); + numberB();    cout << sum;}int main(){    sum();    return 0;}

## Replies

 mo elsaid · January 12, 2015 thank you c student (: , i got it Earl Hudson · January 17, 2015 I glad you have it figured out, but being new to C++, I'd still like to take a shot at it.You have two functions, and you never call them, being VOID they can't return a value. This is my solution.``#include using namespace std;int numberA(){   int a;    cout << "Give me a number please " ;    cin >> a;    return a;};int numberB(){    int b;     cout << "Give me another number " ;     cin >>b;     return b;}; void sum(int a,int b){     int answer=a+b;     cout << "The sum of the two numbers is " << answer << endl;};int main(){int firstnum = numberA();int secondnum = numberB();    sum(firstnum,secondnum);    return 0;}``How did I do? c student · January 17, 2015 c++ is too confusing.  never gonna do it in my life...``#include int numberA (void) {    return std::cin.get()-'0';}int numberB (void) {    std::cin.ignore();    return std::cin.get()-'0';} void sum (int (*numA)(void), int (*numB)(void)) {     std::cout << "The sum of the two numbers is " << (*numA)() + (*numB)() << std::endl;}int main (void) {    sum (numberA, numberB);    return 0;}`` c student · January 11, 2015 1. you have no return types/values for each function,2. you never declared a sum variable in sum function, 3. the line ``int numberA(); + numberB(); // what is the int for? your semicolon is declaring // the end of a statement in mid-statement``is incorrect.
• 1

## C++

129,919 followers