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.
//
// program2.cpp
// cs
//
//
#include <cstring>
#include <iostream>
usingnamespace 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;
elseif(tempchar == 'h' && progress == 1)
progress = 2;
elseif(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;
}
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 ;)