0
#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');


}

Edited by happygeek: fixed formatting

3
Contributors
4
Replies
5
Views
12 Years
Discussion Span
Last Post by Asif_NSU
0

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

0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.