Hello thar, I'm having trouble with Programming again (not my best class, I utterly fail at math). If you would be so kind, we have to use a Loop to count the number of vowels in a string of text that is entered into a text box, then displayed into a label. I tried a few ideas, with none of them working; this is what I have so far, it probably looks stupid, but hey, I suck at Programming;
[code] Dim vowcount As Integer
Do
If txtvowel.Text.Substring(1) = "a" Then
vowcount = vowcount + 1
End If
Loop Until txtvowel.Text.Substring(100)
lblcount.Text = vowcount[/code]
Please help guys, I'm really frustrated with this.
What language? (I'm assuming VB.NET)
This would be my method:
[code]
Dim mrCount, i as Integer
Dim vowels() as String
Dim theWord as String
Dim tempArray() as String
vowels = new String() {"a", "e", "i", "o", "u"} //y?
For i = 0 To vowels.Length-1
tempArray = theWord.Split(vowels(i))
if tempArray.Length > 1 then
mrCount += tempArray.Length
end if
Next i
[/code]
It's mostly pseudo code, I don't know VB.Net very well.
[QUOTE=Benjy355;18175524]What language? (I'm assuming VB.NET)
This would be my method:
[code]
Dim mrCount, i as Integer
Dim vowels() as String
Dim theWord as String
Dim tempArray() as String
vowels = new String() {"a", "e", "i", "o", "u"} //y?
For i = 0 To vowels.Length-1
tempArray = theWord.Split(vowels(i))
if tempArray.Length > 1 then
mrCount += tempArray.Length
end if
Next i
[/code]
It's mostly pseudo code, I don't know VB.Net very well.[/QUOTE]
Yeah, it is VB. Thanks for the help, but I used an array for another project (we hadn't covered arrays in class yet) and the teacher had accused me of cheating. I would love it if someone could find another way to do this.
he accused you of cheating? he's fucking stupid. what if you already knew/read a couple tutorials in your free time about arrays, that's not cheating..
[QUOTE=Ca5bah;18175608]Yeah, it is VB. Thanks for the help, but I used an array for another project (we hadn't covered arrays in class yet) and the teacher had accused me of cheating. I would love it if someone could find another way to do this.[/QUOTE]
...Hmm.
[code]Dim mrCount, i as Integer
Dim theWord as String
Dim letter as String
For i = 0 To theWord.Length
letter = theWord.Substring(i, 1)
If letter = "a" Then
mrCount++
End If
If letter = "e" Then
mrCount++
End If
If letter = "i" Then
mrCount++
End If
If letter = "o" Then
mrCount++
End If
If letter = "u" Then
mrCount++
End If
Next i[/code]
?
PS. I'd call this cheating :P
[QUOTE=efeX;18175726]he accused you of cheating? he's fucking stupid. what if you already knew/read a couple tutorials in your free time about arrays, that's not cheating..[/QUOTE]
The teacher is a she, but yeah, figure that out. She thinks that there is no way we would possibly do tutorials outside of class. I suck at programming and HAVE to do tutorials outside of class to keep up. I'm an English/Visual Design person, not a Math/Science person.
[QUOTE=Ca5bah;18175818]The teacher is a she, but yeah, figure that out. She thinks that there is no way we would possibly do tutorials outside of class. I suck at programming and HAVE to do tutorials outside of class to keep up. I'm an English/Visual Design person, not a Math/Science person.[/QUOTE]
There is no 'cheating' in programming. Arrays are basic data structures, it'd be stupid if you are not allowed to use them when they could be efficiently applied.
[QUOTE=Clavus;18175861]There is no 'cheating' in programming. Arrays are basic data structures, it'd be stupid if you are not allowed to use them when they could be efficiently applied.[/QUOTE]
My teacher doesn't think that, otherwise I would not have gotten bitched out by her. She thinks that anyone who doesn't do the program to her exact specifications must be using code from kids who have already taken the class.
Please, I would love it if someone could show me how to do the aforementioned problem without using an array.
Use the Mid function and loop through to the total # of chars in the sentence.
[code]
Dim Count, i as Integer
Dim Word, Vowels as String
Vowels = "aeiou"
Count = 0
Word = "stuff"
For i = 0 To word.Length-1
if Vowels.IndexOf(Word.Substring(i, 1)) != -1)
Count += 1
End If
Next i[/code]
No idea if that is proper VB though. I'm used to C#, and they are somewhat similar when it comes to function names and such.
[QUOTE=Ca5bah;18175946]My teacher doesn't think that, otherwise I would not have gotten bitched out by her. She thinks that anyone who doesn't do the program to her exact specifications must be using code from kids who have already taken the class.
Please, I would love it if someone could show me how to do the aforementioned problem without using an array.[/QUOTE]
Someone already did it.
[QUOTE=Benjy355;18175812]...Hmm.
[code]Dim mrCount, i as Integer
Dim theWord as String
Dim letter as String
For i = 0 To theWord.Length
letter = theWord.Substring(i, 1)
If letter = "a" Then
mrCount++
End If
If letter = "e" Then
mrCount++
End If
If letter = "i" Then
mrCount++
End If
If letter = "o" Then
mrCount++
End If
If letter = "u" Then
mrCount++
End If
Next i[/code]
?
PS. I'd call this cheating :P[/QUOTE]
Also if you can explain to her how arrays and your solution which uses arrays work, I fail to see how she could accuse you of cheating. Do that (unless you can't explain them)
Thanks guys, I figured it out this morning. Get this though, I used the StringBackwards command to reverse a string of text, and she marked me down for not doing it manually, which would've require an extra 2-4 lines of code.
You could also get the length, remove all the vowels, and then find the difference.
I don't know Vb but it would look like this in java:
[cpp]
String word;
int vowCount;
for (int i ; i<=word.length(); i++)
{
char tempChar;
tempChar = word.charAt(i);
if (tempChar == "a" || tempChar == "e" || tempChar == "i" || tempChar == "o" || tempChar == "u")
{
vowCount++;
}
}
[/cpp]
Clocks incoming ;D
[QUOTE=micropro;18199838]I don't know Vb but it would look like this in java:
[cpp]
String word;
int vowCount;
for (int i ; i<=word.length(); i++)
{
char tempChar;
tempChar = word.charAt(i);
if (tempChar == "a" || tempChar == "e" || tempChar == "i" || tempChar == "o" || tempChar == "u")
{
vowCount++;
}
}
[/cpp]
Clocks incoming ;D[/QUOTE]
That's wrong. In Java you must initialize local variables before using them.
[QUOTE=Robber;18200367]That's wrong. In Java you must initialize local variables before using them.[/QUOTE]
Didn't know that. But why? All variable have initial values, don't they?
Anyway:
[cpp]
String word = " ";
int vowCount = 0;
for (int i = 0 ; i<=word.length(); i++)
{
char tempChar " ";
tempChar = word.charAt(i);
if (tempChar == "a" || tempChar == "e" || tempChar == "i" || tempChar == "o" || tempChar == "u")
{
vowCount++;
}
}[/cpp]
[url]http://java.about.com/od/understandingdatatypes/a/declaringvars.htm[/url]
You need to initialize the variables [i]before[/i] usage, as such you don't have to initialize word, as you'll probably get the users input or something and tempChar could be initialized directly as word.charAt(i).
Eh, never mind. I think I'm learning C next semester.
[QUOTE=Ortzinator;18197749]You could also get the length, remove all the vowels, and then find the difference.[/QUOTE]
String.Replace is often shifty when replacing letters beside other letters. (In my experiences)
THE FUCK? MY AVATAR IS HOFF
[QUOTE=Ortzinator;18197749]You could also get the length, remove all the vowels, and then find the difference.[/QUOTE]
That's actually a pretty good idea, I'd never have thought of that.
Sorry, you need to Log In to post a reply to this thread.