Help Me,My Program is not working.

I have written a program which creates student record with structures. program so that it will display a menu for the
user to choose either to;
Add student records
Update student records
View all student records
Find a student by ID

The program also enables user to
modify the name of the selected student.

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
  #include <cstdlib>
#include <iostream>
#include <iomanip>

using namespace std;                    

struct student
{
	string ID;
	string name;
	string nick;
};

struct course
{
	string code;
	string name;
	string lecname;
};

void displaymenu(){
cout<<"===========================================<<"\n";
cout<<" MENU "<<"\n";
cout<<"==========================================="<<"\n";
cout<<" 1.Add student records"<<"\n";
cout<<" 2.Update student records"<<"\n";
cout<<" 3.View all student records"<<"\n";
cout<<" 4.Find a student by ID"<<"\n"; 
}

void add_rec(struct student st[],struct course st[],int& itemcount){

again:
cout<<"\nEnter student's ID:";
cin>>st[itemcount].ID;
if(search(st,st[itemcount].ID,itemcount)!=-1){
cout<<"This ID already exists\n";goto again;
}

cout<<"Enter student's Name:"; 
cin>>st[itemcount].name;
cout<<"Enter student's Nickname:";cin>>st[itemcount].nick;
cout<<"Enter student's course code:";cin>>st[itemcount].code;
cout<<"Enter student's course name:";cin>>st[itemcount].name;
cout<<"Enter student's course lecturer name:";cin>>st[itemcount].lecname;


st[itemcount].total=st[itemcount].code+st[itemcount].name+st[itemcount].lecname;

++itemcount;

}

void viewall(struct student st[],struct course st[],int& itemcount){
   int i=0;
  cout<<left<<setw(5)<<"ID"<<setw(20)<<"NAME"<<setw(5)<<"NICKNAME"
  <<setw(5)<<"COURSE CODE"
  <<setw(5)<<"COURSE NAME"<<setw(5)<<"LECTURER NAME"<<setw(5)<<"\n";
   cout<<"==========================================\n";
  while(i<=itemcount){
     if(st[i].stnumber!=""){
        cout<<left<<setw(5)<<st[i].stnumber<<setw(20)<<st[i].stname<<setw(5)
       <<st[i].nick;
       cout<<setw(5)<<st[i].code<<setw(5)<<st[i].name<<setw(5)<<st[i].lecname<<setw(5)<<st[i].total;

      cout<<"\n";}
      i=i+1;

}


}

void update_rec(struct student st[],struct course st[],int& itemcount){
  string id;
  int column_index;
  cout<<"Enter student's ID:";
  cin>>id;
  cout<<"Which field you want to update(1-6)?:";
  cin>>column_index;

  int index = search(st, id,itemcount);

  if (index != -1)
   {
    if (column_index == 1)
     {
      cout<<"Enter student's Name:";

      cin>>st[index].name;
     }

  else if (column_index == 2)
   {
    cout<<"Enter student's Nickname:";
    cin>>st[index].nick;
    }
  else if (column_index == 3)
   {
   cout<<"Enter student's course code:";
   cin>>st[index].code;
  }
  else if (column_index == 4)
  {
   cout<<"Enter student's course name:";
   cin>>st[index].name;
 }
  else if (column_index == 5)
   {
     cout<<"Enter student's course lecturer name:";
     cin>>st[index].lecname;
     }

  
  
  
 
  else cout<<"Invalid column index";

  st[index].total = st[index].code + st[index].name + st[index].lecname;


  }
  else cout<<"The record deosn't exits.Check the ID and try again.";


}

int main(int argc, char *argv[])
{


student st[80];
int itemcount=0;

//show menu
displaymenu();
int yourchoice;
char confirm;
do
{
cout<<"Enter your choice(1-4):";
cin>>yourchoice;

switch(yourchoice){
case 1:add_rec(st, itemcount);break;
case 2:update_rec(st, itemcount);break;
case 3:viewall(st, itemcount);break;
case 4:find(st, itemcount);break;

default:cout<<"invalid";


}
cout<<"Press y or Y to continue:";
cin>>confirm;
}while(confirm=='y'||confirm=='Y');
system("PAUSE");
return EXIT_SUCCESS;
} 
Last edited on
But the program is not working

Can you expand on this a little??

edit: and don't use goto. use a loop instead.

edit2: what is search? Are you trying to use std::search? if you need to
 
#include <algorithm> 

but i'm not sure what you're passing in will work.

also stuff like this:
 
st[i].stnumber


your student structure doesn't even have a variable called "stnumber".

Last edited on
Topic archived. No new replies allowed.