V
V
Valery2019-11-12 17:03:19
Arrays
Valery, 2019-11-12 17:03:19

What is wrong with c++ program?

In general, the task is:
5dcabb542c10e584144910.jpeg
Here is the code:
The if (txt[k] == arrchar[l]) condition is not fulfilled at all, what could be the problem?)))

#include <iostream>
#include <string>
#include <windows.h>
#include <stdio.h>


using namespace std;
int main()
{
  SetConsoleCP(1251); // настраиваем кодировку консоли (ввод)
  SetConsoleOutputCP(1251); // (вывод)

  // настраиваем внутренние механизмы на эту кодировку
  setlocale(LC_ALL, ".1251");

  char txt[100];
  int j = 0;
  int k = 0;
  int l = 0;
  char arrchar[33] = { 'а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я' };
  char arrchar2[33] = { 'б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я','а' };
  cin.getline(txt, sizeof(txt));
  //шифруем
  while (txt[0 + j] != 0) {
    while (txt[k] != arrchar[l]) {
      if (txt[k] == arrchar[l]) {
        cout << arrchar[l+1];
        l = 0;
        k++;
      } 
      else if(l==32) {
        l = 0;
        k++;
      }
      else {
        l++;
      }
    }
    j++;
  }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question