# Help creating pronunciation program

**URL:** <https://discourse.processing.org/t/help-creating-pronunciation-program/18453>\
**Category:** Coding Questions\
**Created:** [March 6, 2020, 5:59pm UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453 "2020-03-06T17:59:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Burgs](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Burgs](https://discourse.processing.org/u/Burgs)\
**Post date:** [March 6, 2020, 5:59pm UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/1 "2020-03-06T17:59:32Z")

</div>

i need help finishing an assignment, it includes getting input from the user and scanning each letter/character to see where it corresponds to with my if statements and printing out the pronunciation of the word in the console.

```auto
import javax.swing.JOptionPane;

String enterWord;

int i = 1+

void setup(){
  size(1000,550);
  background(200);
  noLoop();
}

  void draw(){

enterWord = JOptionPane.showInputDialog("Please enter a Hawaiian word, or quit to stop");

for (enterWord.charAt(i);){

if ( p ){

} else if (k){
  
} else if (h){

} else if (l){

} else if (m){

} else if (n){

} else if (w){
  
} else if (a){
    if(ai){
      println();
    } else if(ae){
      println();
    } else if(ao){
      println();
    }
} else if (e){
    if(ei){
      println();
    } else if(eu){
      println();
    }
} else if (i){
    if(iu){
      println();
    }
} else if (o){
    if(oi){
      println();
    } else if(ou){
      println();
    }
} else if (u){
    if(ui){
      println();
    }
}

}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 6, 2020, 6:38pm UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/2 "2020-03-06T18:38:54Z")

</div>

You are doing it a little wrong

use a normal for(int i=0; i\<enterWord; i++) {

then if(enterWord.charAt(i)==‘p’) {…

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 6, 2020, 6:42pm UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/3 "2020-03-06T18:42:38Z")

</div>

Repeat for every if clause

(Just copy the expression)

---

<div class="post-metadata">

**Author:** ![Burgs](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Burgs](https://discourse.processing.org/u/Burgs)\
**Post date:** [March 6, 2020, 6:51pm UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/4 "2020-03-06T18:51:33Z")

</div>

> [@Chrisir](#):
>
> if(enterWord.charAt(i)==‘p’)

great thanks, though i get this error on the console,

> “The operator \< is undefined for the argument type(s) int, String”

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 6, 2020, 6:55pm UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/5 "2020-03-06T18:55:53Z")

</div>

> [@Chrisir](#):
>
> for(int i=0; i\<enterWord; i++) {

for(int i=0; i\<enterWord.length(); i++) {

My bad

---

<div class="post-metadata">

**Author:** ![Burgs](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Burgs](https://discourse.processing.org/u/Burgs)\
**Post date:** [March 6, 2020, 7:01pm UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/6 "2020-03-06T19:01:30Z")

</div>

sweet thanks got that but now this is what I have and im getting a constant error?

the error says

> “Invalid character constant”

and its red underlined at

```auto
    } else if(enterWord.charAt(i)=='aw'){
      println("w");

```

* * *

```auto
 void draw(){

enterWord = JOptionPane.showInputDialog("Please enter a Hawaiian word, or quit to stop");

for(int i=0; i < enterWord.length(); i++)
  
  if(enterWord.charAt(i)=='p') {
  println("p");
} else if (enterWord.charAt(i)=='k'){
  println("k");
} else if (enterWord.charAt(i)=='h'){
  println("h");
} else if (enterWord.charAt(i)=='l'){
  println("l");
} else if (enterWord.charAt(i)=='m'){
  println("m");
} else if (enterWord.charAt(i)=='n'){
  println("n");
} else if (enterWord.charAt(i)=='p'){
  println("p");
  if(enterWord.charAt(i)=='w'){
      println("w");
    } else if(enterWord.charAt(i)=='aw'){
      println("w");
    } else if(enterWord.charAt(i)=='iw'){
      println("v");
    } else if(enterWord.charAt(i)=='ew'){
      println("v");
    } else if(enterWord.charAt(i)=='uw'){
      println("w");
    } else if(enterWord.charAt(i)=='ow'){
      println("w");
    }
} else if (enterWord.charAt(i)=='a'){
  println("ah");
    if(enterWord.charAt(i)=='ai'){
      println("eye");
    } else if(enterWord.charAt(i)=='ae'){
      println("eye");
    } else if(enterWord.charAt(i)=='ao'){
      println("ow");
    } else if(enterWord.charAt(i)=='au'){
      println("ow");
    }
} else if (enterWord.charAt(i)=='e'){
  println("eh");
    if(enterWord.charAt(i)=='ei'){
      println("ay");
    } else if(enterWord.charAt(i)=='eu'){
      println("eh-oo");
    }
} else if (enterWord.charAt(i)=='i'){
  println("ee");
    if(enterWord.charAt(i)=='iu'){
      println("ew");
    }
} else if (enterWord.charAt(i)=='o'){
  println("oh");
    if(enterWord.charAt(i)=='oi'){
      println("oy");
    } else if(enterWord.charAt(i)=='ou'){
      println("ow");
    }
} else if (enterWord.charAt(i)=='u'){
  println("oo");
    if(enterWord.charAt(i)=='ui'){
      println("ooey");
    }
}

}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 6, 2020, 7:03pm UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/7 "2020-03-06T19:03:50Z")

</div>

In this Method you check only one char not two

For checking two letters look at subString in the reference

---

<div class="post-metadata">

**Author:** ![Burgs](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Burgs](https://discourse.processing.org/u/Burgs)\
**Post date:** [March 6, 2020, 7:07pm UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/8 "2020-03-06T19:07:07Z")

</div>

ah i see but i want it to print the output based on what the user types in not a preset output

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 6, 2020, 7:54pm UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/9 "2020-03-06T19:54:15Z")

</div>

Nothing to do with this. Substring is just a way to look at two Strings

Or what do you mean?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 7, 2020, 6:03am UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/10 "2020-03-07T06:03:48Z")

</div>

I understand now.

It’s a little difficult though because sometimes you read 1 letter and sometimes 2. Totally logical but a bit harder for computers.

The approach we have now wouldn’t work now fully because of this. It would work when we would only use 1 letter.

Also hard because you check for ai and a alone (for example).

**To solve this:**

Don’t use for loop but while. Check first only two letter occurrences.

- When you have a match set a boolean marker to true.

Increase i by 2 (!)

- When you don’t have a match start checking for 1 letter occurrences. Increase i by 1.

Chrisir

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [March 9, 2020, 4:34am UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/11 "2020-03-09T04:34:53Z")

</div>

@Burgs – welcome to the forum! When you post, please help us help you by [formatting your code](https://discourse.processing.org/faq#format-your-code) with the `</>` button or by putting ``` above and below your code.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 16, 2020, 4:38pm UTC](https://discourse.processing.org/t/help-creating-pronunciation-program/18453/12 "2020-03-16T16:38:42Z")

</div>

here is an example of the idea above

```auto

//https://discourse.processing.org/t/help-creating-pronunciation-program/18453

import javax.swing.JOptionPane;

String enterWord;

//int i = 1; 

void setup() {
  size(1000, 550);
  background(200);
  println("");
  noLoop();
}

void draw() {

  enterWord = JOptionPane.showInputDialog("Please enter a Hawaiian word, or quit to stop");

  int i=0;

  while ( i<enterWord.length()) {

    boolean marker=false; 

    if (i<enterWord.length()-3) {
      if (enterWord.substring(i, i+2).equals("ai")) {
        print("AI");
        marker=true;
        i += 2;
      }
    }

    // ----------------

    if (! marker) {
      // println ("here");  
      if (enterWord.charAt(i)=='u') {
        //
        println("U");
      }//if
      i++;
    }
  }//while
  //
  println("");
  //
}//func 
//

```
