repeating characters

At the moment my code will turn this:
[b][italic]hello world our time is up now[/italic][/b]
into
[b][italic]Hello World our Time is up Now[/italic][/b]
It will turn the first letter of a word to upper case unless it is a vowel.Presently if the first input letter is a vowel the program will fail. At the moment I'm not dealing with that but do plan to fix it so that either a vowel or a normal letter can be input as the first letter

What I am trying to do at the moment is make it so that there are no repeating characters so [b][italic]hello[/italic][/b] would become [b][italic]Helo[/italic][/b]. The thing that is driving me nuts here is how would this be done so that repeating vowels are left alone so that [b][italic]meet[/italic][/b] would become [b][italic]Meet[/italic][/b]. Im stumped and would be thankful for any help.

My code at the moment is:[code]#include

using namespace std;


int main ()
{
char ch;


cout<<"Enter a series of words"<<endl;
cin.get( ch );

if(!((toupper(ch) == 'A') || (toupper(ch) == 'E') || (toupper(ch) == 'I') ||
(toupper(ch) == 'O') || (toupper(ch) == 'U')))

{
ch = toupper ( ch );

while ( ch != '
' )
{
if ( isspace ( ch ) )
{
cout<<" ";

while ( isspace ( ch ) )
cin.get( ch );

if (!((toupper(ch) == 'A') || (toupper(ch) == 'E') || (toupper(ch) == 'I')
|| (toupper(ch) == 'O') || (toupper(ch) == 'U')))
{
ch = toupper ( ch );
cout<<ch;
}
else
cout << ch;
}
else
cout<<ch;
cin.get( ch );
}
}

cout << endl;

return 0;
}
[/code]

Comments

  • Hey,

    you must have a second char

    char c2 = ' ';

    and than in your last else:

    else
    {
    if (ch != c2)
    {
    cout<<ch;
    c2 = ch;
    }
    cin.get( ch );
    }

    I think so it must be OK.
    Sabst
  • [b][red]This message was edited by Tragan at 2002-11-2 1:54:40[/red][/b][hr]
    Thanks for the input.

    I got it to do want I wanted now.


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories