• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Help me a little bit more with C++ coding?

Walleye

Banned
alright.. i'm trying to create a program that will convert a sentence into pig-latin.

here's the rules for the conversion that i'm using.

if the first letter is a vowel, then the word is unchanged, and onto the end is added "yay".

if the second letter is a R or an H, then both the first and second letter move to the end, and add on "ay".

else, the first letter goes to the back, and adds on ay as normal.


here's what i got so far.

the wierd thing is that when i run it, if i put a vowel in the first letter position, it's broken,... i havent tried the r or h in the second letter position, but the strings "hello world" returned helloyay. so obviously it isnt working.

any ideas where to start looking?
 
Well first of all you are asking the user to input a sentance one word at a time which is into reall entering a sentence, take the whole string and tokenize it into words using whitespace or a semicolon or a coma as a delimieter.

Then make a function to check if its a vowel instead of having 10 or clauses and make sure you use == not =;

decalre your char pa and char pb at the top of the function

and make sure you check for empty strings so you may want to do a trim on the words if you choose not tokenize an entire sentance.
 
Originally posted by: toekramp
pfffh we would have been hit up with an honor code violation at VT if we posted something like this

You are assuming that it was his homework.
 
also
use std::getline to input a whole sentence. It's simpler than whatever you were doing in your program
std::getline(cin, englishword)
(since you're in namespace std, you may omit the std:🙂
Don't forget to remove the whitespaces
and next time, post this in Software, Programming forum
 
Originally posted by: neilm
What's the best c++ environment to be working under, Visual C++ .NET? Dev C++? or something else?

I've used both, and they're good, but for anybody who's just learning, DEV gets the edge - mostly cause it's free 🙂 . VC is going to set you back at least $100, and a lot more if you can't get it through something like a University bookstore or other campus software deal.

EDIT: hate to say this, but the one caveat for DEV is that the debugger sucks in 4.98 (a.k.a version 5 beta). It's much better in the the older 4.x version, though. I do like the new interface on the beta though.

Nate
 
hmm..

i'm writing this in emacs and using the g++ compiler. i dont have a debugger or anything of that nature. thanks for the help all 🙂

and no, this isnt my homework, it was some in class practice that i didnt finish in class. i wanted to finish it up, but didnt understand why things weren't working.

if you noticed, i write this while telnetted into my school.
 
Originally posted by: Walleye
hmm..

i'm writing this in emacs and using the g++ compiler. i dont have a debugger or anything of that nature. thanks for the help all 🙂

and no, this isnt my homework, it was some in class practice that i didnt finish in class. i wanted to finish it up, but didnt understand why things weren't working.

if you noticed, i write this while telnetted into my school.

gdb is your debugger then.
http://www.gnu.org/manual/gdb-4.17/gdb.html

If you can use X either in the labs locally or through a tunnel, you could try ddd, a graphical frontend for gdb (and dbx, etc).
http://www.gnu.org/software/ddd/
 
WTF do you do with a word like "argument"? Your rules don't cover it. Do you leave it unchanged because it starts with a vowel, or do you move the first two letters to the end since the second letter is 'R'?
 
i assumed that it would follow the first rule because it came first. hence, the else. meaning IF the first one weren't true.
 
If you get into the habit of writing comparisons as
if (CONSTANT==value)
then you'll never get this error again.
compile-time-errors>runtime errors.
 
Originally posted by: CorporateRecreation
Didn't I forsee this pattern weeks ago when he begged people to do his code?

i hardly call 2 occassions spread over more than a month a "pattern".

EDIT: and i didnt beg anybody to do my code. i asked for a bit of help. it still took me about 4 hours to figure the whole thing out. but i did get it working. and noone did the work for me.
 
Originally posted by: Walleye
Originally posted by: CorporateRecreation
Didn't I forsee this pattern weeks ago when he begged people to do his code?

i hardly call 2 occassions spread over more than a month a "pattern".

EDIT: and i didnt beg anybody to do my code. i asked for a bit of help. it still took me about 4 hours to figure the whole thing out. but i did get it working. and noone did the work for me.

Right since one of my close friends here did it for you. Go lie to people who still care about your trite meaningless life.

PS: Brian's code was 1/3 of the space of yours and twice as effecient and easier to read.
 
Originally posted by: notfred
WTF do you do with a word like "argument"? Your rules don't cover it. Do you leave it unchanged because it starts with a vowel, or do you move the first two letters to the end since the second letter is 'R'?

In that case, here's the entire program, in a language more suited to ding this sort of thing:

#!/usr/bin/perl
use strict;
print "Enter sentance: ";
my $sentance = <>;
my @words = split /\s+/, $sentance;
foreach my $word(@words){
if($word =~ s/^([aeiou].*)/$1yay/i){}# Empty blocks looks funny,
elsif($word =~ s/^(.[rh])(.*)/$2$1ay/i){}# But they work in this case.
else{($word =~ s/^(.)(.*)/$2$1ay/i)}
print "$word ";
}
print "\n";
 
Originally posted by: CorporateRecreation
Originally posted by: Walleye
Originally posted by: CorporateRecreation
Didn't I forsee this pattern weeks ago when he begged people to do his code?

i hardly call 2 occassions spread over more than a month a "pattern".

EDIT: and i didnt beg anybody to do my code. i asked for a bit of help. it still took me about 4 hours to figure the whole thing out. but i did get it working. and noone did the work for me.

Right since one of my close friends here did it for you. Go lie to people who still care about your trite meaningless life.

PS: Brian's code was 1/3 of the space of yours and twice as effecient and easier to read.

maybe it was more efficient. does it matter? I thank people who helped me, but in the end, i turned in an original code. i mean sh1t, there's hundreds of ways of doing the same thing. noone did my homework for me. i ran over others code to see why and how it worked, but like i said, in the end, i turned in an original code.





oh, back to the matter.

the damage isnt as bad as i thought. it works completely, except for the fact it's completely missing the last word. so if i enter
"hello world"

it returns
"ellohay".

and i enter
"Hello world how are you today"

it returns
"ellohay orldway owhay areyay ouyay".

wierd. i suppose i could request the user to input an extra word on the end, though. that would at least offer full functionality. but how do i get the last word to work?
 
Back
Top