#include<iostream.h>
#include<conio.h>
int main()
{
int a[5],loc,val,ans;
do
{
cout<<" enter the elements "<<endl;
for(int i=0;i<5;i++)
cin>>a;
cout<<" enter the location u want to edit with respect to zero ";
cin>>loc;
cout<<" enter the val to be inserted ";
cin>>val;
for(int j=6;j<0;j--)
{       if(j==loc)
a[j]=val;
else if(j>loc)
a[j]=a[j-1];


}
for(int k=0;k<6;k++)
cout<<a[k]<<endl;
cout<<" press y to continue ";
cin>>ans;
}while(ans=='y'||ans=='Y');


}

Recommended Answers

All 4 Replies

I think the line of code:

for (int j = 6; j < 0; j--)

should be

for (int j = 6; j > 0; j--)

Thank you i do silly mistakes, but m still not able to make it menu driven , the prog stops execution after i press y

that's because your ans is of type int. Try this instead:

char ans

.
In C char literals like 'y' and 'Y' are actually of type int, but in C++ they are of type char.

And try to declare your array atleast a size greater than the total no of elements entered initially.

In C char literals like 'y' and 'Y' are actually of type int, but in C++ they are of type char.

Sorry, this actually has nothing to do with this program. It's just cin fails to read ans because a char has been given instead of an int.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.