Need Help With My Code

So pretty much all I have to do is put a "-" between any double vowels that are in the word that I input into the array. So far I am able to get the word spread out to where it needs to be without the dash in the middle of the vowels. I just can't find a way to put them in now.

Example:
Text inputted: heeeeellllooooo

result: he e e e ellllo o o o o

except in the middle of the vowels when I print the result, it shows a character I'm not familiar with. its not a space. Sorry if you are confused by what I'm trying to do. Thank you for any input.



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
  #include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

void main()
{
int i, z;
i = 0;

char text[100],resulttext[120];
const char text1 = '-';

cout << "Please enter any text here: ";
cin >> text;


for (int ii = 0; ii < 120; ii++)
{
	int z = ii + i;
	if (text[ii] == 'a')
	{
		if (text[ii + 1] == 'a') // checks for an 'a' in the array
		{
			i = i + 1;
		}
	}
	if (text[ii] == 'u') // checks for an 'u' in the array
	{
		if (text[ii + 1] == 'u')
		{
			//resulttext[ii] = text1;
			i = i + 1;
		}
	}
	if (text[ii] == 'e') // checks for an 'e' in the array
	{
		if (text[ii + 1] == 'e')
		{
			//resulttext[ii] == text1;
			i = i + 1;
		}
	}
	if (text[ii] == 'i') // checks for an 'i' in the array
	{
		if (text[ii + 1] == 'i')
		{
			//resulttext[ii] == text1;
			i = i + 1;
		}
	}
	if (text[ii] == 'o') // checks for an 'o' in the array
	{
		if (text[ii + 1] == 'o')
		{
			//resulttext[ii] == text1;
			i = i + 1;
		}
	}
	resulttext[z] = text[ii];

}
cout << resulttext << endl;
}
Last edited on
closed account (48T7M4Gy)
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
#include <iostream>
#include <string>

int main()
{
  char vowel[] = {'a', 'e', etc };
  bool found = false ;
  
  std::string word = "hello";
  
  for( int i = 0; i < word.length; i++ )
  {
    found = false;
    for (int j = 0; j < 5; j++)
    {
        if ( word[i] == vowel[j] )
            found = true;
    }
    
    if ( found = true)
        std::cout << '-';
        
    std::cout << word[i];
  }
  
  return 0;
}
A few things to tidy up and a small addition to take into account double vowels not just single ones. (Hint: count them as they are encountered )

Or, even better adapt a couple of my lines only to your code to get the std::cout << '-' to work.
Last edited on
Topic archived. No new replies allowed.