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
#include<iostream>
#include<iomanip>
#include "elem.h"
usingnamespace 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;
}
}