This is basically my code. It says build succeed, but I get nothing. What am I doing wrong.

The user inputs a sentence, for example, Hello. (I've taken out other parts such as return LOWERCASE, return DIGIT, and what would happen in those cases for ease of reading).

The program should then encrypt accordingly but it's not doing that. It would take the first character, pass that through my function getTypeOfChar.

It runs, but it comes out with nothing when i input a sentence. I've tried a for loop with array, but no matter what the currentChar doesnt seem to pass to the function

#include <iostream>
#include "ctype.h"
#include <string>


using namespace std;


const int UPPERCASE = 0;
const int OTHER = 5;


string storedSentence;


void storeChar(char aChar);

void printStoredSentence();


char getTypeOfChar(char aChar) {
    
    if (int(aChar) >= 65 && int(aChar) <= 90) 
        return UPPERCASE;
    
            
    return OTHER;
}

void encryptor() {
    
    
    char sentence[200];
        

    cout << "Please enter the sentence to be encrypted: " << endl;
    cin.getline( sentence, 200, '\n');

    char currentChar = 0;    
    char encryptedChar = 0;
    do {
        
            
            // Don't know how to read the character from the sentence and pass it below to the function/switch statement
                        
        
        switch (getTypeOfChar(currentChar)) {
            case UPPERCASE:
                if (currentChar == 'Z') {
                    encryptedChar = 'a';
                } else {
                    
                    encryptedChar = int(tolower(currentChar)) + 1;
                }
                break;
            default:
                encryptedChar = currentChar;
                
        }
        

        storeChar(encryptedChar);
    } while (currentChar != '\n');

    printStoredSentence();
}


void decryptor() {

        char sentence[200]

    cout << "Please enter the sentence to be decrypted: " << endl;
        cin.getline( sentence, 200, '\n');

    char currentChar = 0;
    char decryptedChar = 0;
        
    do {

        // Don't know how to read the character from the sentence and pass it below to the function/switch statement

        switch (getTypeOfChar(currentChar)) {
            case UPPERCASE:
                if (currentChar == 'A') {
                    decryptedChar = 'z';
                } else {
                     decryptedChar = int(tolower(currentChar)) + 1;
                }
                break;
            default:
                 decryptedChar = currentChar;
        }
        storeChar(decryptedChar);
    } while (currentChar != '\n');

    printStoredSentence();
}

int main() {
    bool shouldContinue = true;

    do {
        int choice = 0;    

        
        cout << "Please select:" << endl;
        cout << "1. Encrypt a sentence" << endl;
        cout << "2. Decrypt a sentence" << endl;
        cout << "3. Exit" << endl;
        cout << "Your choice:";

        
        cin >> choice;
        
        cin.get();
        switch (choice) {
            case 1:
                
                encryptor();
                break;
            case 2:
                
                decryptor();
                break;
            case 3:
                
                shouldContinue = false;
                break;
            default:
                
                cout << "Please input 1, 2 or 3" << endl;
        }
    } while (shouldContinue);

    return 0;
}



void storeChar(char aChar) {
    
    storedSentence += aChar;
}

void printStoredSentence() {
    cout << storedSentence << endl;
    
    storedSentence.clear();
}
This article has been dead for over six months. Start a new discussion instead.