Я вроде как новичок в C++ ... имел класс около месяца или около того ... Anywho, мы делаем этот окончательный проект, где мы должны сделать шифрования/дешифрования с использованием метода шифрования холма. Я столкнулся с небольшой проблемой, когда, когда я пытаюсь вернуть числа из функции, она отображает символы вместо фактических чисел. Однако сама функция работает правильно. Несмотря на то, что это домашняя работа/классная работа, учитель позволяет нам использовать онлайн-источники и внешнюю помощь, поскольку, как я уже говорил, мы программировали только месяц или около того. Любая помощь будет очень признательна!Как преобразовать буквы в строку в числа - C++
#define NOMINMAX
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <windows.h>
#include <Windows.h>
#include <chrono>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
int random1()
{
unsigned long long int xRan;
srand(time(NULL));
again:
xRan = rand() * 319/43 * 16 * 333 % 9999 + 1;
if (xRan <= 0)
goto again;
return xRan;
}
int random2()
{
unsigned long long int xRan;
srand(time(NULL));
again:
xRan = rand() * 319 * 43/16 * 321 % 9999 + 1;
if (xRan <= 0)
goto again;
return xRan;
}
int random3()
{
unsigned long long int xRan;
srand(time(NULL));
again:
xRan = rand() * 319/43/16 * 2 % 9999 + 1;
if (xRan <= 0)
goto again;
return xRan;
}
int convert(char conv)
{
return (int)conv-87;
}
int matrixMult(double q, double w, double e)
{
int i, j, k, count = 0, total = 0;
double a, s, z, x, c, v, b, n, m;
a = random1();
s = random2();
z = random3();
x = random1();
c = random2();
v = random3();
b = random1();
n = random2();
m = random3();
int A[1][3] = { q, w, e };
int B[3][3] = {
{ a, s, z },
{ x, c, v },
{ b, n, m }
};
for (i = 0; i < 3; ++i)
{
for (j = 0; j < 3; ++j)
{
for (k = 0; k < 3; ++k)
total += A[i][k] * B[k][j];
cout << setw(5) << total << ' ';
++count;
if (count % 3 == 0)
cout << endl;
total = 0;
}
}
return 0;
}
int main()
{
string again = "y";
cout << "Would you like to encrypt or decrypt?(e/d) " << endl;
string ende;
cin >> ende;
if (ende == "e")
{
cout << "Please enter a name for the message: " << endl;
string file;
cin >> file;
file += ".txt";
ofstream encrypt;
encrypt.open(file);
string message;
cout << "Please enter the message you would like to encrypt: " << endl << endl;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
getline(cin, message);
//int length = message.size();
char converted[9999];
for (int i = 0; i < message.length(); ++i)
{
converted[i] = convert(message[i]);
cout << converted[i] << endl;
}
encrypt.close();
cout << "Your message has been encrypted.\nPlease check " << file << " for the encrypted message and key" << endl;
}
if (ende == "d")
{
cout << "0";
}
return 0;
}
только 'int convert [9999];'. Вы объявили его как char, поэтому он печатает символы – ForceBru
. Эти gotos могут быть заменены петлями do-while – ryanpattison
OMG gotos !!! 1! – chmike