A
A
ashot_powershot2021-11-01 13:36:23
C++ / C#
ashot_powershot, 2021-11-01 13:36:23

variable char. It seems like I replaced the letters, but the text is not displayed. Why?

Through step-by-step debugging, you can see that the replacement is taking place, but only a dot is displayed on the screen. You need to replace 'a' with 'b' and 'b' with 'a'.

#include<iostream>
#include <cstring>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<conio.h>


using namespace std;
int main()
{
  setlocale(LC_ALL, "RUS");

  char bukva;
  bool proverka = false;
  int i = 98,x=97;
  cout << "Введите текст = " << endl;
  do {
    cin >> bukva;
    if (bukva == 'a')
    {
      proverka = true;
    }
    if (proverka)
    {
      char bukva = i;
      proverka = false;
    }
    if (bukva == 'b')
    {
      proverka = true;
    }
    if (proverka)
    {
      char bukva = x;
      proverka = false;
    }
  } while (bukva != '.');
  cout << "Текст после изменений = " << bukva << endl;
  
  system("PAUSE");
  
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-11-01
@wataru

Note that you are outputting bukva, which contains only one character. One character is displayed.
In general, judging by this code - quit programming. This is not for you. You have a joint there in every second line.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question