如何输入一个单词,并将其移动6个字母?它只是立即返回0 [英] How do I input a word, and shift it 6 letters? It just return 0 instantly

查看:66
本文介绍了如何输入一个单词,并将其移动6个字母?它只是立即返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

using namespace std;

string encrypt (string cde);

int main()
{
    char A, B, C, letter, vault;
    string temp, ENC;
    start:
    cout << "Choose task: " << endl;
    cout << endl;
    cout << "A. Encrypt" << endl;
    cout << "B. Decrypt" << endl;
    cout << "C. Exit Program"<< endl;
    cout << endl;
    cin >> letter;
    system ("CLS");

    if  (letter == 'A' )
    {
        string cde, ENC;
        int shift;
        cout << "Please enter a message: ";
        getline(cin, cde);

        string temp = cde;
        int length;
        length = (int)temp.length();
        for (int i = 0; i < length; i++)
        {
            if (isalpha(temp[i]))
            {
                for (int j = 0; j < 6; j++)
                {
                    if (temp[i] == 'z')
                    {
                        temp[i] = 'a';
                    }
                    else if (temp[i] == 'Z')
                    {
                        temp[i] = 'A';
                    }
                    else
                    {
                        temp[i]++;
                    }
                }
            }
        }

        cout << "\nEncoded message: " << temp << endl;
    }


    else if (letter =='B' )
    {
        s2:
        cout << "B" << endl;
    }
    else if (letter == 'C')
    {
        s3:
        return 0;
    }

    else
    {
        cout << "Invalid Input.";
        Sleep(500);
        system ("CLS");
        goto start;
    }
    return 0;
}





我的尝试:



我已经尝试将它与其他代码集成,但它不会工作。

它只是立即显示返回0

i想先输入一个单词然后移动它然后显示移位的单词



What I have tried:

I've tried integrating it with other codes but it wont work.
it just displays return 0 instantly
i wanted to input a word first then shift it then display the shifted word

推荐答案

您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到有一点它会停止你所期望的。

在Visual Studio 2010中掌握调试 - 初学者指南 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]


这篇关于如何输入一个单词,并将其移动6个字母?它只是立即返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆