i am a really beginner in C++ programming
(and are in a really great despairr from my programming test 1 mark that i just got lately...WhatEver...)
I'm just wondering..for the following code:
//create array of ten length
char array[10];
//initialize array prompt user
cout<<"insert ten character separated by space"<<endl;
for(int i = 0;i<10;i++)
cin>>array[i];
cout<<endl;
//deleting an array element
//prompt user to insert what index to be deleted
char index;
cout<<"insert element index to be deleted";
cin>>index;
cout<<endl;
(p.s:i'm not giving the whole code program as i just want to focus on above code)
the problem is if the user input more than 10 character,the balance character will go into the next input variable=index..how to remove these excess input..? so that the excess input won't automatically inserted into the index variable?
e.g
user input=a b c d e f g h i j k l m
excess input=k l m
Can't you just add an if statement and another variable before you input to index?.
For example:
1 2 3 4 5 6 7 8 9 10 11
char index;
char indexTester;
cout<<"insert element index to be deleted";
cin>>indexTester;
if(indexTester == a or indexTester == b or indexTester == c or indexTester == d or indexTester == e or indexTester == f or indexTester == g or indexTester == h or indexTester == i or indexTester == j
{
index = indexTester;
}
else
{
cout << "please choose a different letter" << endl;
Is this what you are asking to do? It basically makes sure that the input is a - j and not higher than j before writing it to the index variable.