Generation of tokens in cpp circular alphabet spaces error

0

I'm having a problem with a program in cpp that when the user enters a number greater than 3 or that enters 4 or 5 when the letter c is greater az does not return to the letter to bone does not subtract the numbers just like indicate in the code and in "c" it puts a value to me all crazy that is changing depending on how many spaces are skipping respercto to "b" I imagine I am not allowed to use loops or cycles.

#include <iostream>

using namespace std;

int main( ){
  char a, b, c, d, e, f, g;
  int num1, num2, num3, esp1, esp2;

  cout << "Introduzca el espacio entre letras y luego el espacio entre numeros";
  cin >> esp1;
  cin >> esp2;
  cou t<< "Introduzca la primera letra de su token y el primer numero de su token";
  cin >> a;
  cin >> num1;

  if( esp1 >= 2 && esp1 <= 5 && esp2 >= 1 && esp2 <= 6 ) {
    b = a + esp1;
    c = b + esp1;
    num2 = num1 + esp2;
    num3 = num2 + esp2;

    if( num2 > 9 ) { num2 -= 10; }
    if( num3 > 9 ){ num3 -= 10; }
    if( b > 122 ) { b -= 26; }
    if( c > 122 ) { c -= 26; }

    switch( num3 ) {
    case 0: d = 'a'; break;
    case 1: d = 'b'; break;
    case 2: d = 'c'; break;
    case 3: d = 'd'; break;
    case 4: d = 'e'; break;
    case 5: d = 'f'; break;
    case 6: d = 'g'; break;
    case 7: d = 'h'; break;
    case 8: d = 'i'; break;
    case 9: d = 'j'; break;
    default: break;
    }

    cout << a << b << c << d << num1 << num2 << num3;
  } else {
    cout << "No se puede generar un token con esos valores";
  }
}
    
asked by Carlos Hernandez 03.11.2018 в 03:15
source

0 answers