Formatting

Hello all! I was supposed to write a program that ask for an input of 4 numbers and it uses Boolean functions to tell if certain thing about a character is true or not. I've got all the code working perfectly but I'm supposed to format it vertically instead of going down horizontally. Im supposed to use escape sequences for it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  /*
chartest.cpp

*/

#include <iostream>

using namespace std;

bool isupper(char c);
//return true if c is an uppercase letter
bool isalnum(char c);
//returns true if character is a digit or letter
bool isalpha (char c);
//returns true if character is a letter
bool islower(char c);
//returns true if character is lowercase
bool isdigit(char c);
//returns true if character is a digit

int main() {

    char c1, c2, c3, c4;
    cin >> c1 >> c2 >> c3 >> c4;

    cout <<'\t' << "isupper" << '\t' << '\n';
    cout << c1 << '\t' << isupper(c1) << '\n';
    cout << c2 << '\t' << isupper(c2) << '\n';
    cout << c3 << '\t' << isupper(c3) << '\n';
    cout << c4 << '\t' << isupper(c4) << '\n';

    cout << '\t'<< "isalnum" << '\t'<< '\n';
    cout << c1 << '\t' << isalnum(c1) << '\n';
    cout << c2 << '\t' << isalnum(c2) << '\n';
    cout << c3 << '\t' << isalnum(c3) << '\n';
    cout << c4 << '\t' << isalnum(c4) << '\n';

    cout << '\t'<< "isalpha" << '\t'<< '\n';
    cout << c1 << '\t' << isalpha(c1) << '\n';
    cout << c2 << '\t' << isalpha(c2) << '\n';
    cout << c3 << '\t' << isalpha(c3) << '\n';
    cout << c4 << '\t' << isalpha(c4) << '\n';

    cout << '\t'<< "islower" << '\t'<< '\n';
    cout << c1 << '\t' << islower(c1) << '\n';
    cout << c2 << '\t' << islower(c2) << '\n';
    cout << c3 << '\t' << islower(c3) << '\n';
    cout << c4 << '\t' << islower(c4) << '\n';

    cout << '\t'<< "isdigit" << '\t'<< '\n';
    cout << c1 << '\t' << isdigit(c1) << '\n';
    cout << c2 << '\t' << isdigit(c2) << '\n';
    cout << c3 << '\t' << isdigit(c3) << '\n';
    cout << c4 << '\t' << isdigit(c4) << '\n';

    return 0;
}

bool isupper(char c) {
    if( c >= 'A' && c <= 'Z') return true;
    return false;

}

bool isalnum(char c) {
    if ((c >= '0' && c <= '9')||( c >= 'A' && c <= 'z' )) return true;
    return false;
}

bool isalpha(char c) {
    if ( c >= 'A' && c <= 'z' ) return true;
    return false;
}

bool islower(char c) {
    if ( c >= 'a' && c <= 'z' ) return true;
    return false;
}

bool isdigit( char c) {
    if ( c >= '0' && c <= '9') return true;
    return false;
}
Last edited on
If you don't want it on a new line omit the '\n' (new line character).
Topic archived. No new replies allowed.