[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Programming advice
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 21
Thread images: 3
File: advice.png (15 KB, 849x351) Image search: [Google]
advice.png
15 KB, 849x351
Does anyone know what i'm doing wrong here? won't run and comes up with an error saying there's an expected expression before ||
>>
>>51808168
Check your parentheses, the || is outside of the if(...).
>>
>>51808168
you spelled capitalize wrong.
>>
You need encapsulating outer parens on your entire if clause, broheim
>>
you aren't nesting your 'if' statement properly

/* you have: */
if ((name[0] >= 'P') && (name[0] <= 'S')) || ((name[0] >= 'p') && (name[0] <= 's'))

/* should be */
if ((name[0] >= 'P') && name[0] <= 'S') || (name[0] >= 'p' && (name[0] <= 's'))
>>
>>51808220
also, this.
>>
jesus christ programming is confusing that's why i am liberal arts major
>>
>>51808321
xkcd?
>>
File: advice 2.png (14 KB, 827x295) Image search: [Google]
advice 2.png
14 KB, 827x295
>>51808223
>>51808226
>>51808233
>>51808245
>>51808220
I changed it to this, is there anything else I need to do? what do you mean by || being out of the "if" statement, and how do i include it?
>>
File: fixed.png (16 KB, 869x404) Image search: [Google]
fixed.png
16 KB, 869x404
nevermind i got it, thanks 4 chan. I don't know how many times i've used this website, but i'd be lost without it!
>>
>>51808462
Jesus.
>>
>>51808462
glad to help. know that I accidentally added too many parenthesis and you can get by with just

if ((name[0] >= 'P' && name[0] <= 'S') || (name[0] >= 'p' && name[0] <= 's'))

if ( (this & that) OR (this & that) )


keep at it, mate
>>
>>51808524
you don't have to but here's my skype; harrison.king5 if it's okay you can add me, and if i have troubles in the future then i might ask, although i understand if that's too much
>>
youre using an ide
>>
>>51808168
missing a parens in if clause line 10
>>
>>51808233
That's wrong, retard.
>>
ASCII A: 65 - 90
ASCII a: 97 - 122
/*
This function returns the lower case of a character if it is an upper case character.
*/
char lowerChar(char c) {
return c >= 97 && c <= 122 ? c - 32;
}
// your code, now without repeating yourself:
char curr = lowerChar(name[0]);
if (curr >= 'p' && curr <= 's') {
// your code here
}

// And this is how I would code it myself:
if (lowerChar(name[0]) >= 'p' && lowerChar(name[0]) <= 's') {
// your code here
}
>>
>>51809218
Ah forgot to finish my ternary in the function. Typo, just need to return c if it's not an upper case letter.
Fix:
char lowerChar(char c) {
return c >= 97 && c <= 122 ? c - 32 : c;
}
>>
>>51809218
>>51809238
the C standard library already includes `tolower'
>>
Try using an editor that highlights matching parentheses when you move the cursor over them.
>>
>>51808462
Not like it really makes a big difference in your code, but you might find getting familiar with toupper/tolower makes things that aren't case sensitive easier.
You essentially get to get rid of the OR.
Thread replies: 21
Thread images: 3

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.