adding new element in the array

i dont now what to do else;
i have afunction that will read data from the screen and then save it un the array.
and another function that will print whatever happen to the arrays
my prog runs perfectuly but at function print it dosent print the new data added
this is function add data:
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
void AddStud()
{    cout <<"hi"<<endl;
	int addID;
	cout<<"enter the id :"<<endl<<endl;
	cin>>addID;
	
	int choice;
  
   existance= SearchData(addID);
	   
        
		    while (existance==true)
			{
			cout <<"****error*******the student already exists.Enter 1 to provide another id or 0 to go to the menu: "<<endl<<endl;
			cin>>choice;
			
		     if(choice ==1)                                 
			  {	                                            
			                                                        
				  cout<<"id is :";                                         
			      cin>>addID;                                                       
				  existance = SearchData(addID); }
			 if(choice == 0)
			 {
				 return ;}

			 
			}//end of while                                                               
	   
			 if (existance==false)
			{   i+=1;//incrementing each time the index of all the arrays to insert the data
//where i is number of element of the array
				cout<<"Enter First Name :";
				cin>>Fname[i];
				cout <<endl;
				cout <<"Enter major : ";
				cin>>Major[i];
				cout<<endl;
				cout <<"enter GPA ";
				cin >>GPA[i];
				cout <<endl;
				cout << "enter total credits : ";
				cin >>HRS[i];
				cout<<endl;

	  cout <<"****data added****"<<endl<<endl;
			}
			 cout<<"i " <<i<<endl;
}//end of the function 

this is the other functrion prin:
1
2
3
4
5
6
7
8
9
10
11
12
13
void StopPrint()
{
	cout << "***Thank you***.Here is the final report on student data**"<<endl;
	cout <<setw(8) <<"Student ID "<<setw(8)<<"Major"<<setw(8)<<"GPA"<<setw(6)<<"HRS"<<endl;
	 cout<<"i " <<i<<endl;
      for (int x=0;x<50;x++)
	  {
		 if(SID[x]!=0)
		  cout <<setw(8) <<SID[x]<<"      "<<Major[x]<<setw(9)<<GPA[x]<<setw(8)<<HRS[x]<<endl;
		
	  }

}//end of function 


please can any one help me.
why it print only the data that was read from file
Where and how are you defining these arrays that you're insterting elements into?
Show the function that reads in the data from file.
Are these arrays global?
yes global this is the porgram but by parts so to not get confused::
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
# include <iostream>
# include <fstream>
# include <string>
# include <iomanip>

using namespace std;


//declaring global arrays
int SID[50];//to store ID
string Fname[50];//to store the firsit name
string Major[50];
float GPA[50];
int HRS[50];

//declare function prototype

void RedaData();
//precondition:open the files that have the data
//the size of the array is fixed
//postcondition:save all data into the apropreiat array
void DisplayMenu();
//it will give the user some options to select
//precondition:the option selected must be in the rang
//or give apropriate error massage
//postecondition:depending on the choice of the function call 
//that function
void FindStud();
//precondition:get the student id from the user
//serch for the id in the array 
//postcondition:display the stud info on the screen
void AddStud();
//precoondition:the stud id must cheeack if it eixist befor adding 
//stud info
//get the info from the user
//postconditon:add the info to each of the five array 
void DeletStud();
//precondition:ask the user for the id that is wanted to be deleted
//serch 4 the id
//set the studID to 0, the actual data is the same 
//but during printing the summary we will use  the cv bzero
//postcondition:record will be deleted
void StopPrint();
//precondition:deleted recordes where the id is set to 0 will not be 
//printed or saved.
//postcondition:print the final report of the student in the screen and the output file
bool SearchData(int);
//precondition:get the id nuumber
//serch the id in the array 
//postcondition:return abool valu true if the id eixist. 

     ifstream inData;
     int i;
	 bool existance;
int main()
{
  RedaData();
  DisplayMenu();
	return 0;
}

this where i will read from file:
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
void RedaData()
{
	//declaring function scoop variabels
	int ID,TH;
	string FirstName,MajorStud;
	float GPAstud;

	//open the file inData
	inData.open("studInput.txt");
	if(inData.fail())
	{
		cout<< "cannot open the file"<<endl;
		return ;}
	//red the first line from the file
	inData>>ID>>FirstName>>MajorStud>>GPAstud>>TH;

	

    while(inData)
	{
       for(int x=0;x<=49;x++)
	   {
		   
		   cout<<ID<<endl;//'\t'<<FirstName<<'\t'<<MajorStud<<'\t'<<GPAstud<<'\t'<<TH<<endl;
		       SID[x]=ID;
			   Fname[x]=FirstName;
			   Major[x]=MajorStud;
			   GPA[x]=GPAstud;
			   HRS[x]=TH;
        inData>>ID>>FirstName>>MajorStud>>GPAstud>>TH;
		
		if(!inData)
			break;
		i++;

	   }
	}
}//end of void function 

thank you jRaskell for your help.

Topic archived. No new replies allowed.