I had to pick through with a fine tooth comb to figure out those loops.
Try adding a comment to each scope opening brace and closing brace, naming each scope on the opening brace, then on the closing brace state which scope just closed.
You can not compare C strings (character arrays) using the == operator. What happens when you do is that you compare the address (pointer) to the first element in the string. The array pagn and the string literal "y" is not stored at the same location in memory so pagn == "y" will always be false.
To compare two C strings you should use the strcmp function from the <cstring>. Another possibility is to use the string class, which allows you to compare strings using == like you do in your program.
I think char is supposed to be only single quotes, like so 'y' while strings are double quotes like so "y" at least in visual studio that rule is a must.
Also, I know I can compare char with char, and do so in several programs, but in single quotes and as singles, not arrays.
Also, maybe I missed it, but I don't see any reason for pagn to be an array, thus make it only one char and switch to single quotes and that should work.
@Peter87 by string class do you mean including the library then creating the variable as a string? and whenever i remove the quotes it says y is not declared
This is a c string, which is just an array of char, inlcudes a closing null char, pagn is a pointer to array, pagn[0] is the first char of the array,
char pagn[2] = "y";
This is just a single char,
char pagn = 'y';
This is a string class,
string pagn = "y";
The double quotes indicate a string (probably denotes the inclusion of the closing null char, but I can't be sure), while single quotes are for single char, which because they are single, they don't require a closing null char nor a pointer.