Structure Help

In this program, i need to input student particulars eg. Name, sex, exam results.
So i have used structure to input information with the help of functions. However the information is only kept temporary on that particular function and if i prompt for it outside the funtion, it will give a wrong output. The code which i did are as follows and i will trully appreciate if some kind soul will help.



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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>

using namespace std;


struct student{
string name;
int age;
string sex;
};


void inf(student a);
void display(student a);



int main()
{
    student a;



    inf(a);
    display(a);



    return 0;
}




void inf(student a){



    cout<<"Enter name: "<<endl;
    cin>>a.name;

    cout<<"Enter age: "<<endl;
    cin>>a.age;


    cout<<"Enter sex: "<<endl;
    cin>>a.sex;



}


void display(student a){


    cout<<a.age<<endl;



}




I managed to do it. Thank you sir!
Topic archived. No new replies allowed.