I want to write a program to prompt the user to enter a multi-dimensional array of characters after specifying the element he wants to use and after the 2nd entry the program should ask the user if he wants to change a certain element entry. Now everything goes smoothly until the user answers with a 'y' before entering an invalid character (say he entered z an error massage will appear and the program will ask him again, if he enters 'y' this time the program continues as supposed to) please help me out here :) ( and if you know a certain code to make the user only able to enter 'y' or 'n' that would be awesome to share ;) )
here's the source code:
#include<iostream>
using namespace std;
void enteries(char[5][5]);
char arr[5][5];
void main(){
enteries(::arr);
}
void enteries(char ent[5][5]){
int i,j;
char x;
for(int z=1; z<26;z++){
cout<<"Please, specify the cell you want to enter data into \n"<<endl;
cout<<"Row [0-4] : "<<" ";
cin>>i;
for(;i<0||i>4;){
cout<<"error:out of boundaries \n"<<"please enter a valid row number \n";
cin>>i;
if(i<0||i>4){
continue;}
else
break;
}
cout<<"Column [0-4] : "<<" ";
cin>>j;
for(;j<0||j>4;){
cout<<"error:out of boundaries \n"<<"please enter a valid column number \n";
cin>>j;
if(j<0||j>4){
continue;}
else
break;
}
cout<<"Please, enter the character you wish into the specified cell \n"<<endl;
cin>>::arr[i][j];
if (z>=2){
cout<<"Do you want to change an entery [Y/N]?";
cin>>x;
for(;x!='n'&&x!='N';){
if (x!='Y'&&x!='y'){
cout<<"error:invalid character \n"<<"Do you want to change an entery [Y/N]?";
cin>>x;
continue;}
if(x=='y'|| x=='Y'){
cout<<"Please, specify the entery you wish to change \n"<<endl;
cout<<"Row"<<" ";
cin>>i;
for(;i<0||i>4;){
cout<<"error:out of boundaries \n"<<"please enter a valid row number \n";
cin>>i;
if(i<0||i>4){
continue;}
else
break;
}
cout<<"Column"<<" ";
cin>>j;
for(;j<0||j>4;){
cout<<"error:out of boundaries \n"<<"please enter a valid column number \n";
cin>>j;
if (j<0||j>4)
continue;}
cout<<"Please, enter the new data \n"<<endl;
cin>>::arr[i][j];
break;
Sorry for the late reply. I've solved the problem (I don't really know why or how it worked, but apparently rearranging the code did the trick) anyway thanks :)