Passing/Receiving value of variable in a function.

closed account (zwpL3TCk)
Hi! I'm having a problem with function on how to pass it to the other function.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream.h>

void numd() {
int a;
cout << "Enter the number: "
cin >> "a;
}

void display (){
cout << "The number you inpout is: " << numd();
} 


Is this correct?
You need to have a function return a value.

You can use a function in cout, but the functions given would have ridiculous output if you used them that way.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
//to make a function return a value
//you give it a return type and then make sure it returns that type
//using the examples you used I would do something like this
int numd() {
    int a;
    cout << "Enter the number: ";
    cin >> a;
    return a;
}

void display() {
    int a = numd();
    cout << "The number you input is: " << a;
}
Topic archived. No new replies allowed.