Задача С++ №3

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by Qwertison, 16 Jul 2007.

  1. Qwertison

    Qwertison New Member

    Joined:
    1 Apr 2007
    Messages:
    43
    Likes Received:
    4
    Reputations:
    -13
    Хочу зделать шифратор и дешифратор 4-значного числа.
    Шифратор:
    Code:
    #include <iostream.h>                  
    
    main ()
    
    {
    
    float x, y, z, i;
    
     cout << "Chislo:\n ";
    
     cin >> x >> y >> z >> i;
     cout << (z + 7)/10 << (i + 7)/10 << (x + 7)/10 << (y + 7)/10;
    
     return 0;
    
    }
    Дешифратор:
    Code:
    #include <iostream.h>
                                           
    main ()
    
    {
    
     float x, y, z, i;
    
       cout << "Vvod: ";
       cin >> x >> y >> z >> i;
       cout << "Deshifr: " << z*10 - 7 << i*10 -7 << x*10 - 7 << y*10 - 7 ;
    
       return 0;
    
    }
    Где здесь ошибки?
     
    1 person likes this.
  2. n1†R0x

    n1†R0x Elder - Старейшина

    Joined:
    20 Jan 2007
    Messages:
    728
    Likes Received:
    376
    Reputations:
    235
    инсертни во вторую строчку
    Code:
    using namespace std;
    и в след. раз пиши, какие ошибки у тебя выводятся, тут нет телепатов
     
    #2 n1†R0x, 16 Jul 2007
    Last edited: 16 Jul 2007
  3. da_ff

    da_ff Elder - Старейшина

    Joined:
    11 Jul 2006
    Messages:
    118
    Likes Received:
    22
    Reputations:
    26
    добавь в начало строчку using namespace std и следи за порядком вывода чисел он перемешан
     
  4. Noman

    Noman Elder - Старейшина

    Joined:
    10 Oct 2006
    Messages:
    112
    Likes Received:
    23
    Reputations:
    2
    Получилось немного убого, но у меня сейчас мозги ушли в отпуск.
    Code:
    #include <iostream.h>
    #include <conio.h>
    #pragma hdrstop
    
    int main()
    {
     float s, c, a, f, x, y, z, i;
     char c_string[5]; //массив
     cout << "Enter value:\n";
     cin >> c_string;
     int lenFact = strlen(c_string); //получаем длинну строки
     if (lenFact != 4)  //проверка на длинну строки
     {
      cout << "\nInvalid value!";
      cout << "\nPress any key to exit...";
      getch();
      return 0;
     }
     x = (c_string[0] - '0' + 7);
     s = x / 10;
     y = (c_string[1] - '0' + 7);
     c = y / 10;
     z = (c_string[2] - '0' + 7);
     a = z / 10;
     i = (c_string[3] - '0' + 7);
     f = i / 10;
     cout << s << c << a << f;
     cout << "\nPress any key to exit...";
     getch();
     return 0;
    }
    
    А дешифратор - домашнее задание. Не сделаешь его, можешь бросать программирование и идти в кружок по вязанию ;)
     
    #4 Noman, 16 Jul 2007
    Last edited: 16 Jul 2007