i am getting an error " ) expected" on turboc++ v3.0
the program is about to insert and manipulate data into an array.
switch structure is used to drive a menu for different operations.
#include<iostream.h>
#include<conio.h>
class array
{
private:
int ar[20];
public:
void read(int);
void display(int);
void ins(int,int);
int del(int,int);
};
void main()
{
int num=0,exit=1,kth;
array la;
clrscr();
while(exit)
{
int choice;
cout<<"1:enter elements of array/n2:insert an element at kth position/n3:Delete an element from kth position/n4:View all the data stored in array/n5:Exit";
cin>>choice;
switch(choice)
{
case 1:
cout<<"/tenter no. o elements/n";
cin>>num;
la.read(num);
break;
case 2:
cout<<"/nenter the kth position/n";
cin>>kth;
la.ins(kth,num);
break;
case 3:
cout<<"/nenter the kth position/n";
cin>>kth;
cout<<"/nDeleted Item = "<<la.del(kth,num);
break;
case 4:
cout<<"/nelements stored in array/n";
la.display(num);
break;
case 5: exit=0;
default:
cout<<"/ninvalid option/n";
}
}
getch();
}
void array::display(int a)
{
for(int i=0;i<a;i++)
cout<<ar[i];
}
void array::ins(int loc,a) //here is the error" ) expected"
{
int temp;
if(a==0)
cout<<"arrray is empty use 1st option to enter data";
elseif(a==20)
cout<<"Ther is no more space to store more data";
else
cout<<"enter the item";
cin>>temp;
{
for(int i=a;i>loc+1;i--)
ar[i+1]=ar[i];
}
cin>>ar[loc-1];
}
int array::del(int loc,a)
{
if(a==0)
cout<<"there is nothing to delete";
else
{
int temp=ar[loc];
for(int i=loc-1;i<a;i++)
ar[i]=ar[i+1];
}
return temp;
}
void array::read(int a)
{
for(int i=0;i<a;i++)
cin>>ar[i];
}
You need to give a type for each parameter, not just the first one:
1 2 3
void array::ins(int loc,a) // <- 'a' has no type. You need to give it one:
void array::ins(int loc, int a) // <- not it is of type int
Also for the love of God get a different compiler/build environment. Turbo C++ is a dinosaur. It is so old it actually predates the C++ standard, so you're not really even writing C++... you're writing some other language that is kinda-sorta similar to C++ but has way less features, is less consistent and is more buggy.