address book

How can I get the main() to cout the user's response? all answers appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  #include <string>
#include <iostream>
using namespace std;


int total_a = 0;
string user_c;

string intro(char first);
string intro(char first)
{
    if (first == 'f')
    {
        cout<<"create a new address"<<endl;
        cout<<"browse the addresses"<<endl;
        cout<<"delete an address"<<endl;
        cout<<"exit the program"<<endl;
    }
    if (first == 'n')
    {
        cout<<"create"<<endl;
        cout<<"browse"<<endl;
        cout<<"delete"<<endl;
        cout<<"exit"<<endl;    
    }
    cin >> user_c;
    return user_c;    
    
}

int main ()
{

    if (total_a == 0)
    {
        cout<<"you have no current addresses"<<endl;
        intro('f');
    }
    else
    {
        intro('n');
    }
   
    cout<< /*response*/;
    return 0;
}
intro() is returning a string, so you can just print it directly:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main ()
{

    if (total_a == 0)
    {
        cout<<"you have no current addresses"<<endl;
        cout << intro('f') << endl;
    }
    else
    {
        cout << intro('n') << endl;
    }
   
    return 0;
}


or first save it, if you wish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main ()
{
    string response;

    if (total_a == 0)
    {
        cout<<"you have no current addresses"<<endl;
        response = intro('f');
    }
    else
    {
        response = intro('n');
    }
   
    cout<< response <<endl;
    return 0;
}
thanks!
Topic archived. No new replies allowed.