#Flags, If-Else & Switch Case

10 messages · Page 1 of 1 (latest)

magic hatch
#

(New to C++, learning.)
I am working on an Assignment for class, and I need some assistance regarding of the things listed below. I have been experimenting with the code to try and get the results of the pictures I will post in here.

I am not sure where to start on my If and Else chain statements and how to incorporate the flags. Just some tips or pointers is what I am looking for.

The solution/outcome

#
#pragma warning(disable: 4996)
#pragma warning(disable: 6031)
#include <stdio.h>
#include <conio.h>

#ifndef __CHARCODES__
#define __CHARCODES__
// Type codes...
#define LETTER       1
#define NUMBER       2
#define SYMBOL       3

// Sub-type codes...
#define VOWEL        4
#define CONSONANT    5
#define ODD          6
#define EVEN         7
#define UPPER_ASCII  8
#define LOWER_ASCII  9
#endif

int main() {
    char keyStroke = 0;
    int typeCode = -1, subTypeCode = -1;

    // GET THE KEYSTROKE (remember to clean phantoms)
    printf("");
    scanf("\n%c", &keyStroke);
    printf("The character you entered in was \"%c\"\n\n", keyStroke);

    // ANALYZE THE KEYSTROKE (IF, IF-ELSE, IF-ELSE-CHAIN here)
    if (keyStroke == 1) {
        typeCode = LETTER;
    }
    else if (keyStroke == 2) {
        typeCode = NUMBER;
    }
    else if (keyStroke == 3) {
        typeCode = SYMBOL;
    }

    // DISPLAY RESULTS BASED ON SET CODES (SWITCH-CASE)
    switch (keyStroke) {
    case LETTER:

        break;
    case NUMBER:

        break;
    case SYMBOL:

        break;
    }

    _getch();
    return 0;
}
#

The current code and struggles I am having. Not sure what to assign to what.

#

The General Assignment.

magic hatch
#

Code has been updated to my experimentation.

simple coral
#

i'll get you started. for if (keyStroke == 1) { you'll want something like if (isalpha(c)) {

magic hatch
#

Thanks i'll check it out.

magic hatch
#

So I assume I was mistaken that the (keyStroke == 1) is comparing to the

#ifndef __CHARCODES__
#define __CHARCODES__
// Type codes...
#define LETTER       1
#define NUMBER       2
#define SYMBOL       3

I was under the impression that it would equal the LETTER (FLAG)