alter the user input

I have this code here that counts the number of alphabetic letters the user's input,the number of characters total, the number of words and the number of "the" that was used. However now I need to alter the user's input to have two spaces after the end of each period, no spaces between a word or comma and each sentence has to have a capitalized letter and display them at the end. And I'm stuck on the altering part. I briefly started the 2 spaces after each period but it won't display anything.
Any help is appreciated
Thanks in advance.


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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
//  program2.cpp
//  cs
//
//
#include <cstring>
#include <iostream>
using namespace std;



int main ()
{
    char paragraph[100]; //holds the user input
    char change[100]; //holds the array to alter the user input
    int alphabet = 0; //holds the count for # of letters
    int nonalphabet = 0; //character count
    int index = 0; //count for userinput array
    int index2 = 0;
    char tempchar; //define the user array into a char
    int wordcount = 1;
    int thecount = 0;
    int progress = 0;

    
    
    cout<<"please enter a paragraph, enter # to stop anytime: ";
    cin.get(paragraph,100);
    while(tempchar != '#' && tempchar != '\n') //if user enters in # the loop stops
    {
        tempchar = paragraph[index]; //intalize tempchar to the array

    
        
    if(isalpha(tempchar)) //counts the alphabet in the input 
        {
            alphabet++;
        }
    
    
    
    if(tempchar >= 34 && tempchar <= 126) //counts the non alphabet
        {
            
            nonalphabet++;
        }
        
    
    if(isspace(tempchar)) //counts the spaces
        {
            wordcount++;
        }
        
    if (tempchar == 't') //if statement to find the amount of the in the input
        progress = 1;
    else if(tempchar == 'h' && progress == 1)
        progress = 2;
    else if(tempchar == 'e' && progress == 2)
        thecount++;
    else
        progress = 0;
        

        
        
        
        
    
    index++; //increase index everytime
    }
    
    while(tempchar != '#' && tempchar != '\n') //alter the input to have two spaces after each period
    {
        change[index2] = paragraph[index];

        
        
        if(paragraph[index] == '.')
            change[index] = change[++index];

        index2++;
        index++;
        
        
    }
    
    cout <<endl<<endl<< "the number of alphabetic character is   \t:" << alphabet << endl;
    cout << "the total number of characters is   \t:" << nonalphabet << endl;
    cout << "the number of words is   \t:" << wordcount << endl;
    cout << "the number of the in the paragraph is: "<<thecount<<endl;
    
   cout<<change;

    return 0;
}



Last edited on
This might help:

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
    char paragraph[1024]; //Make array for paragraph
    int words = 1; //Number of words
    int characters = -1; //Number of characters
    int alpha = 0; //Number of alphebet letters
    int non_alpha = -1; //Number of non alphabet

    cout << "Enter your paragraph, enter # to abruptly end your paragraph: " << endl;
    cin.getline(paragraph,1024); //Enter your work

    for(int ender = 0;;ender++)
    {
        if(paragraph[ender] == NULL)
        {
            paragraph[ender + 1] = '#';
            break;
        }
    }

    for(int relay = 0;;relay++) //Now counting characters
    {
        if(paragraph[relay] == '#')
        {
            break;
        }
        if(paragraph[relay] != '\n')
        {
            characters++;
        }
        if(paragraph[relay] == ' ')
        {
            characters--;
        }
    }
    cout << "The number of characters in your paragraph is: " << characters << endl;
    for(int relay2 = 0;;relay2++) //Now counting words
    {
        if(paragraph[relay2] == '#')
        {
            break;
        }

        switch(paragraph[relay2])
        {
            case ' ':
            words++;
            break;
            default:
            break;
        }
    }
    cout << "The number of words in your paragraph is: " << words << endl;
    for(int relay3 = 0;;relay3++) //Now counting alphabet and non alphabet
    {
        if(paragraph[relay3] == '#')
        {
            break;
        }
        switch(paragraph[relay3])
        {
            case 'a':
            case 'b':
            case 'c':
            case 'd':
            case 'e':
            case 'f':
            case 'g':
            case 'h':
            case 'i':
            case 'j':
            case 'k':
            case 'l':
            case 'm':
            case 'n':
            case 'o':
            case 'p':
            case 'q':
            case 'r':
            case 's':
            case 't':
            case 'u':
            case 'v':
            case 'w':
            case 'x':
            case 'y':
            case 'z':
            case 'A':
            case 'B':
            case 'C':
            case 'D':
            case 'E':
            case 'F':
            case 'G':
            case 'H':
            case 'I':
            case 'J':
            case 'K':
            case 'L':
            case 'M':
            case 'N':
            case 'O':
            case 'P':
            case 'Q':
            case 'R':
            case 'S':
            case 'T':
            case 'U':
            case 'V':
            case 'W':
            case 'X':
            case 'Y':
            case 'Z':
            alpha++;
            break;
            case ' ':
            break;
            default:
            non_alpha++;
            break;
        }
    }
    cout << "The number of alphabet characters in your paragraph is: " << alpha << endl;
    cout << "The number of non-alphabet characters in your paragraph is: " << non_alpha << endl;

    system("PAUSE");
    return 0;
}
This took me like 30 min...
The part where it counts all the words/alphabets and such works I just need help working on the altering part.
I don't get the what you mean by altering...
So I have to change the users input to display two spaces after the end of each period, no spaces between a word or comma and each sentence has to have a capitalized letter and display them at the end.
Replace all spaces with nothing, replace all periods with a period and two spaces. Not hard enough? No, you also have to capitalize the first letter of each sentence, but try the find and replace stuff first ;)
Last edited on
Oh I could try do that.......might take me some time though....I'll try to do what you have 'said'
Topic archived. No new replies allowed.