Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3697960
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:55:24+00:00 2026-05-19T04:55:24+00:00

I am creating an encoding program and when I instruct the program to create

  • 0

I am creating an encoding program and when I instruct the program to create a 5X5 grid based on the alphabet while skipping over letters that match up to certain pre-defined variables(which are given values by user input during runtime). I have a loop that instructs the loop to keep running until the values that access the array are out of bounds, the loop seems to cause the problem. This code is standardized so there shouldn’t be much trouble compiling it in another compiler. Also would it be better to seperate my program into functions? here is the code:

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<string>
#include<limits>

using namespace std;
int main(){


 while (!cin.fail()) {      

char type[81];
char filename[20];
char key [5];
char f[2] = "q";
char g[2] = "q";
char h[2] = "q";
char i[2] = "q";
char j[2] = "q";
char k[2] = "q";
char l[2] = "q";
int a = 1;
int b = 1;
int c = 1;
int d = 1;
int e = 1;
string cipherarraytemplate[5][5]= {
{"a","b","c","d","e"},
{"f","g","h","i","j"},
{"k","l","m","n","o"},
{"p","r","s","t","u"},
{"v","w","x","y","z"}

};
string cipherarray[5][5]= {
{"a","b","c","d","e"},
{"f","g","h","i","j"},
{"k","l","m","n","o"},
{"p","r","s","t","u"},
{"v","w","x","y","z"}

};





cout<<"Enter the name of a file you want to create.\n";

cin>>filename;


ofstream outFile;
outFile.open(filename);
outFile<<fixed;
outFile.precision(2);
outFile.setf(ios_base::showpoint);
cin.ignore(std::numeric_limits<int>::max(),'\n');






cout<<"enter your codeword(codeword can have no repeating letters)\n"; 

cin>>key;

while (key[a] != '\0' ){

while(b < 6){
cipherarray[b][c] = key[a];

 if (  f == "q" ) {
 cipherarray[b][c] = f;
}

 if ( f != "q" && g == "q"  )
 {
cipherarray[b][c] = g;
}

 if ( g != "q" && h == "q" )
 {
cipherarray[b][c] = h;
}

 if ( h != "q" && i == "q"  )
 {
cipherarray[b][c] = i;
}


 if ( i != "q" && j == "q" ) 
{
cipherarray[b][c] = j;
}

 if ( j != "q" && k == "q" )
 {
cipherarray[b][c] = k;
}

 if ( k != "q" && l == "q" )
 {
cipherarray[b][c] = l;
}
a++;
b++;

}

c++;
b = 1;

}

while (c < 6 || b < 6){

if (cipherarraytemplate[d][e] == f || cipherarraytemplate[d][e] == g || cipherarraytemplate[d][e] == h || cipherarraytemplate[d][e] == i ||
cipherarraytemplate[d][e] == j || cipherarraytemplate[d][e] == k || cipherarraytemplate[d][e] == l){
 d++;                 
}
else {
cipherarray[b][c] = cipherarraytemplate[d][e];
d++;
b++;
}
if (d == 6){
d = 1;
e++;
}
if (b == 6){
c++;
b = 1;
}

}

 cout<<"now enter some text."<<endl<<"To end this program press Crtl-Z\n";

while(!cin.fail()){

 cin.getline(type,81);

outFile<<type<<endl;
}

outFile.close();
}
} 

I know there is going to be some mid-forties guy out there who is going to stumble on to this post, he’s have been programming for 20-some years and he’s going to look at my code and say: “what is this guy doing”.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:55:25+00:00Added an answer on May 19, 2026 at 4:55 am

    An array with the first five letters of the alphabet (a size of 5) can be visualized like so:

    Index 0: a
    Index 1: b
    Index 2: c
    Index 3: d
    Index 4: e
    

    As you can see, the index of the first value is actually zero. This can get confusing!

    char MyCharacterArray[5]; // Initializes a one-dimensional character array with a size of five.
    MyCharacterArray[0] = 'a'; // Sets the first value to a.
    MyCharacterArray[4] = 'e'; // Sets the last value to b.
    MyCharacterArray[5] = `f`; // This will generate errors, as the last index of MyCharacterArray is 4!
    

    A basic loop to run through an array might look like this:

    for (int Index = 0; Index <= 4; Index++)
    {
        // ...
    }
    

    This is where your code runs into trouble. Your while loop uses the equivalent of this:

    while (Index < 6)
    

    Which is the same as this:

    while (Index <= 5)
    

    So on the loop’s last runthrough, where Index is 5, it tries to access a value that is outside the array’s range.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While creating a file synchronization program in C# I tried to make a method
While creating classes in Java I often find myself creating instance-level collections that I
I'm creating opensource GPL H264 encoding lib/app (based on x264) do I need to
I'm creating a link shortening service and I'm using base64 encoding/decoding of an incremented
Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select
Creating hashes of hashes in Ruby allows for convenient two (or more) dimensional lookups.
Creating Traversals for Binary Search Tree with Recursion. void inOrder(void (*inOrderPtr)(T&)) { if(this->left !=
Creating an XPathDocument with referenced DTD sometimes throws a web exception. Why?
When creating a web application, and lets say you have a User object denoting
When creating a criteria in NHibernate I can use Restriction.In() or Restriction.InG() What is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.