I'm currently trying to complete an assignment that has me creating my own functions. I'M NOT ALLOWED TO USE ANY FUNCTIONS AT ALL AND THE ONLY LIBRARY I'M ALLOWED TO USE IS THE <iostream> library.
Currently I thought I was done, but when I entered in the final portion of the project which is to capitalize every letter after a punctuation mark, it didn't work right and would only capitalize the first letter of the new word and fail to do the rest. Next I moved the function call before all the other function calls thinking it could be the order and assigning components of each function that is messing up the other code. When I did this (i'm referencing the ascii table values in my code) it subtracted by 64 ultimately and gave me a parenthesis instead of a capital letter like I want. Could anyone explain/help with me with this code. I'm new and really proud that I made it this far, but I've hit a wall. Thank you!
// no other libraries may be accessed except for namespace
#include <iostream>
usingnamespace std;
void cap_first(char[]); //caps first letter of word only
void cap_front(char[]); // caps first letters of all words after a space
void cap_all(char[]); // caps all letters of the word
void cap_end(char[]); // caps only after periods, exclamations, question marks
int main()
{
//local variables only
char user_word[50];
// char user_word1 = user_word;
cout << "Enter your word (Up to 50 characters) " << endl;
cin.get(user_word, 50, '\n');
cin.ignore(100, '\n');
cout << "This is your word: " << user_word << endl;
cap_end(user_word);
cap_first(user_word);
cout << "Your word with only the first letter capitalized is: " << user_word << endl;
cap_front(user_word); // function call to cap every first letter in word
cap_all(user_word); // function call to cap every letter in word
// cap_end(user_word); // function call to cap every letter after a punctuation
return 0;
}
void cap_first (char uppercase[]) // changes first letter upper case
{
if (uppercase[0] >= 'a' && uppercase[0] <= 'z')
{
uppercase[0] -= 32;
}
}
void cap_front(char firstUpper[])
{
// int len = strupper[];
cout << "Pass 1" << endl;
if (firstUpper[0] >= 'A' && firstUpper[0] <= 'Z')
{
cout << "You've entered an alphabetical value." << endl;
int len = 50;
for( int i = 1; i < len; ++i) // capitalizes ever letter after a space
{
if(firstUpper[i] == ' ')
firstUpper[i+1] -= 32;
}
cout << "Your word with every first letter after a space capitalized is: " << firstUpper << endl;
}
else
cout << "You've entered an incorrect value." << endl;
}
void cap_all (char allupper[])
{
if(allupper[0] >= 'A' && allupper[0] <= 'Z')
{
cout << "You're about to capitalize every letter in this sentence." << endl;
int len = 50;
cout << "Pass 2" << endl;
for(int i = 1; i < len; ++i)
{
if(allupper[i] >= 'a' && allupper[i] <= 'z')
allupper[i]-= 32;
}
cout << "Every letter capitalized looks like this: " << allupper << endl;
}
else
cout << "Unable to capitalize everything, sorry. " << endl;
}
void cap_end(char aftercap[])
{
if(aftercap[0] >= 'A' && aftercap[0] <= 'Z')
{
cout << "Your about to capitalize after every punctution mark." << endl;
int len = 50;
cout << "Pass 3" << endl;
for(int i = 1; i < len; ++i)
{
if(aftercap[i] == '.' && aftercap[i+1] == ' ' && aftercap[i+2] >= 'a' && aftercap[i+2] <= 'z')
aftercap[i+2] -= 32;
elseif(aftercap[i] == '?' && aftercap[i+1] == ' ' && aftercap[i+2] >= 'a' && aftercap[i+2] <= 'z')
aftercap[i+2] -= 32;
elseif(aftercap[i+2] == '!' && aftercap[i+1] == ' ' && aftercap[i+2] >= 'a' && aftercap[i+2] <= 'z')
aftercap[i+2] -= 32;
}
cout << "Your word with capitals after the punctuation marks is: " << aftercap << endl;
}
else
cout << "There were no punctation marks in your word(s). " << endl;
}