Help!!

Ive got this program to work using regular class functions, but when i switch it to class templates i get issues with the while loop(only the menu options would show, soon as i press a number the program ends)
elem.h
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
#ifndef _Data_BOX
#define _Data_BOX

// Declaration for the class PlainBox
template<class itemtype>
class Data
{
  private:
// Data field
  static const int Default_Size=10;
  double vStore[Default_Size];
  int capacity;
  int num_used;
  public:
	  Data ();
	
	bool isFull(int count);
	bool isEmpty(int count1);
	int arrayCapacity();
	int numUsed(int count2);
	void setItem (const itemtype& Entry);
	itemtype getItem (int index);
	int ADD(const itemtype& Entry);
	int PosOfElem(const itemtype& Entry);
	int SetPosOfElem(int pos,int number,int count2);
};


	  template<class itemtype>
	  Data<itemtype>::Data(){
		  capacity=10;
		  num_used=0;
	  }
	  template<class itemtype>
	  bool Data<itemtype>::isFull(int count){
		  if(count==capacity)
			cout<<"Array is Full"<<endl;
		else
			cout<<"Array is not full"<<endl;
		return 0;
	   }
	  template<class itemtype>
	  bool Data<itemtype>::isEmpty(int count1){
		  if(count1==0)
			cout<<"Array is empty"<<endl;
		else
			cout<<"Array is not empty"<<endl;
		return 0;
	  }
	  template<class itemtype>
	  int Data<itemtype>::arrayCapacity(){return capacity;}
	  
	  template<class itemtype>
	  int Data<itemtype>::numUsed(int count2){return count2;}
	  
	  template<class itemtype>
	  void Data<itemtype>::setItem(const itemtype& Entry){
		  vStore[num_used]=Entry;
		  num_used++;
		  
	  }
	  template<class itemtype>
	  itemtype Data<itemtype>::getItem(int index){
		  return vStore[index];
	  }
	  template<class itemtype>
	  int Data<itemtype>::ADD(const itemtype& Entry){
		  vStore[num_used]=Entry;
		  num_used++;
		  return 0;
	  }
	  template<class itemtype>
	  int Data<itemtype>::PosOfElem(const itemtype& Entry){
		  for(int i=0;i<capacity;i++){
			if(vStore[i]==Entry)
			   return i+1;
			}
			cout<<"Error"<<endl;
			return -1;
	  }
	  template<class itemtype>
	  int Data<itemtype>::SetPosOfElem(int pos,int number, int count2){
		  if(pos>count2)
			cout<<"Error"<<endl;
		  else
			vStore[pos-1]=number;
			return 0;
	  }
	

	   
#endif 


lab1.cpp
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
#include<iostream>
#include<iomanip>
#include "elem.h"
using namespace std;
int main( )
{

	int StrgAmt;
	double number,number2,number3,number4;
	int pos;
	char menu;
	int counter=0;
	Data<double> bo;
	
	while(true){
		cout<<"To set array press 1."<<endl;
		cout<<"To print the array press 2."<<endl;
		cout<<"To add an element to array press 3."<<endl;
		cout<<"To check if array is full press 4."<<endl;
		cout<<"To check if array is empty press 5."<<endl;
		cout<<"To check for array capacity press 6."<<endl;
		cout<<"To check the amount of elements used press 7."<<endl;
		cout<<"To find the position of an element press 8."<<endl;
		cout<<"To change element in array press 9."<<endl;
		cout<<"If you are done enter exit."<<endl;
		cin>>menu;

		
		if(menu==1){
			cout<<"How many elements do you want? : ";
			cin>>StrgAmt;
			for(int i=0;i<StrgAmt;i++){
			cout<<"Fill in the array: "<<endl;
			cin>>number;
			bo.setItem(number);
			counter++;
			}
		}
		
		if(menu==2){
			cout<<"-------------------"<<endl;
			for(int j=0;j<counter;j++){
			cout<<setprecision(0)<<bo.getItem(j)<<endl;
			
			}

		}
		if(menu==3){
			cout<<"What number do you want to add? "<<endl;
			cin>>number2;
			bo.ADD(number2);
			bo.getItem(counter);
			counter++;

		}
		if(menu==4){
				bo.isFull(counter);
		}

		if(menu==5){
			bo.isEmpty(counter);
		}
		if(menu==6){
			cout<<"The array capacity is "<<bo.arrayCapacity()<<endl;
			
		}
		if(menu==7){
			cout<<"Elements used is: "<<bo.numUsed(counter)<<endl;
		}
		if(menu==8){
			cout<<"Enter number you want to search: "<<endl;
			cin>>number3;
			if(bo.PosOfElem(number3)== -1)
				cout<<bo.PosOfElem(number3)<<endl;
				
			else
				cout<<"Number "<<number3<<" is in position "<<bo.PosOfElem(number3)<<endl;
				
		}
		if(menu==9){
			cout<<"What position do you want to change?"<<endl;
			cin>>pos;
			cout<<"What number do you want to change it to?"<<endl;
			cin>>number4;
			bo.SetPosOfElem(pos,number4,counter);
		}


	return 0;
}
}
Post the errors you get
I suspect you forgot to change line 11. Should the type of the array be itemType?
closed account (iN6fizwU)
Should menu be an int?
@Radio4:
Yes, change menu to an int.
Topic archived. No new replies allowed.