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 8551773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:16:09+00:00 2026-06-11T14:16:09+00:00

I am using this program to implement Mono alphabetic cipher. The problem i am

  • 0

I am using this program to implement Mono alphabetic cipher. The problem i am getting is when i input plain text it doesn’t get out of the loop when condition is met which is pressing the enter key.Here is my code.

int main()
{
    system("cls");
    cout << "Enter the plain text you want to encrypt";
    k = 0;
    while(1)
    {
        ch = getche();
        if(ch == '\n')
        {

            break; // here is the problem program not getting out of the loop
        }
        for(i = 0; i < 26; i++)
        {
            if(arr[i] == ch)
            {
                ch = key[i];
            }
        }
        string[k] = ch;
        k++;
    }
    for(i = 0;i < k; i++)
    {
        cout << string[i];
    }
    getch();
    return 0;
}
  • 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-06-11T14:16:10+00:00Added an answer on June 11, 2026 at 2:16 pm

    Here the problem is probably the fact that getche() (unlike getchar()) just returns the first character when there are more then one inputed and you are on windows (othewise you wouldn’t use cls) then the EOL is encoded with \r\n.

    What happens is that getche() returns \r so your break is never actually executed. You should change it to getchar() even because getche is a non standard function.

    You can even try to look for \r instead that \n in your situation but I guess the \n would remain in the buffer causing problems if you need to fetch any additional input later (not sure about it).

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

Sidebar

Related Questions

Here are the full codes that I am using to implement this program. Everything
I'm using QT to implement some UI program. In this program I need a
I need to write this program using a loop https://i.stack.imgur.com/gko6T.jpg this is what i
For this program #include <iostream> using std::cout; struct C { C() { cout <<
I created this program: #include <iostream> #include <fstream> using namespace std; int main ()
I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I'm working on a picture select/crop program and using this code below: http://www.androidworks.com/crop_large_photos_with_android/comment-page-1#comment-969 As
I'm using a SQL Server database in my program with Linq-to-SQL I'm using this
I have created this simple program to learn shared_ptr using namespace std; #define Yes
I'm using a vector in my program like this: vector<vector<string> > values; values[0].push_back(test words);

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.