Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#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;
}


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
Posted
Updated 12-Mar-16 19:57pm
v3
Comments
Richard MacCutchan 13-Mar-16 6:39am    
Do not use goto in your code, it almost always leads to bugs. Use a proper do or while loop.
Arthur V. Ratz 20-Mar-16 11:00am    
Are you sure you know what exactly are you doing in your code. Normally you have to provide a loop shifting mechanism to shift 6 letters of any words.

1 solution

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[^]
 
Share this answer
 
Comments
Arthur V. Ratz 21-Mar-16 2:11am    
5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900