Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Whorehay

macrumors 6502a
Original poster
Feb 17, 2008
631
1
Been working at this part of the assignment for over 12 hours in a span 3 days now. Just can't get it to work. Not due for another 2 days so not too worried (probably will go to office hours tomorrow). But I thought I'd take one last crack at it before I take it in.

For this part of the assignment, we gotta capitalize every every first letter of the word and lowercase everything else using while loops, and ASCII numbers.

I feel like I'm sorta close, but not close enough to get a substantial reading from the output.

When I enter: "hello its whorehay"
my output is: "HHHHHHHHHHHHHHHHHH"
i'm assuming that the number of h's corresponds to the length of the string.. i'm stuck!

any hints? don't need to shout out the answer since i get a rush when i can figure it out by myself, but any hints toward the right direction would be greatly appreciated. thanks!
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Don't you wanna update position in here?:
Code:
    } else { // or else
         first = false; // set to false
    }

Also, rather than increment inside each case, increment once at the end of the while block. Or better yet, use a for loop.
 

Whorehay

macrumors 6502a
Original poster
Feb 17, 2008
631
1
when i put position++ after what you mentioned, i get the same output. i had it there before but i started playing around with the code after it didn't work. this code is just what i had last (might not be the best).

so it'd be something like?
Code:
for (position = 0; position < length; position++);
hmm i may have to try that later
 

Whorehay

macrumors 6502a
Original poster
Feb 17, 2008
631
1
Wait. Upon closer examination, you sure you don't want that second "if" to be an "else if"?

Code:
 if (first == false) {       // first is false

if you are talking about that line.. i couldn't figure out how to make it an else/else if without a syntax error. (else without if error). played around with the brackets and still came up with the error. so i just left it as if for now so it can at least compile.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
if you are talking about that line.. i couldn't figure out how to make it an else/else if without a syntax error. (else without if error). played around with the brackets and still came up with the error. so i just left it as if for now so it can at least compile.
Code:
if (expression1)
{
    ...first block of code here...
}
else if (expression2)
{
    ...second block of code here...
}

You're brace matching looks a little messed up. Take, for example:
Code:
  if (first == true) {            // boolean for if 
    } if ((c >= 97) && (c <= 122)) { // if it's lowercase
That's an empty if block after the () and second if: { }
I'd suggest reformatting / re-indenting your code to make it easier to match opening and closing braces. Makes it easier to read too!
 

Whorehay

macrumors 6502a
Original poster
Feb 17, 2008
631
1
haven't been able to get for loops to work:

output becomes:

"HELLOmy NAMEis WHOREHAY"

i am CLOSE though. i can feel it. thanks for the help! i appreciate it.
 

Whorehay

macrumors 6502a
Original poster
Feb 17, 2008
631
1
got it! :) :)

thanks for the bracket tip. helped me visualize the pseudo code!
 

Whorehay

macrumors 6502a
Original poster
Feb 17, 2008
631
1
damn it feels good. just organized the entire code and it looks so great that it brings a tear to my eye.
 

Burtonsnow9

macrumors regular
Feb 22, 2008
137
0
Now I don't see your code anymore, but you may want to try a different approach. Make a char array and then for each char check if it is uppercase, and based on that, and the char position (where you are in the words) you can change it to upper or lower case. Use the api for more help.


P.S. - If this was in your original code then sorry.
 

AUFan

macrumors newbie
Feb 2, 2008
27
0
Been working at this part of the assignment for over 12 hours in a span 3 days now. Just can't get it to work. Not due for another 2 days so not too worried (probably will go to office hours tomorrow). But I thought I'd take one last crack at it before I take it in.

For this part of the assignment, we gotta capitalize every every first letter of the word and lowercase everything else using while loops, and ASCII numbers.

I feel like I'm sorta close, but not close enough to get a substantial reading from the output.

When I enter: "hello its whorehay"
my output is: "HHHHHHHHHHHHHHHHHH"
i'm assuming that the number of h's corresponds to the length of the string.. i'm stuck!

any hints? don't need to shout out the answer since i get a rush when i can figure it out by myself, but any hints toward the right direction would be greatly appreciated. thanks!

You could simplify the problem greatly if you break it down into smaller subsections and tackle those. Perhaps use something like substrings and divide all your words up then tackle it that way instead of trying to cram everything through at once.
 

Whorehay

macrumors 6502a
Original poster
Feb 17, 2008
631
1
You could simplify the problem greatly if you break it down into smaller subsections and tackle those. Perhaps use something like substrings and divide all your words up then tackle it that way instead of trying to cram everything through at once.

that's how i solved it. i split the assignment into two sections, the counting of the characters and the printing of the changed sentence. :) haven't learned about arrays yet! still in intro to programming.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.