be me

> be me
> be programming in college
> I look at the screen of the guy next to me
> mfw its 10 lines of strcmp() testing each possible case
> mfw CS graduate meme is real
can people be this dumb senpai

If you want to code you can take a workshop and learn in a few months then get a job, if you want to bullshit your way through a traditional 4 year program with B's then you're going to have a bad time.

Nice, dude. Who are you quoting though?

Did someone actually write that program in earnest or is it just a forced meme?

Please be honest with yourself when answering

I swear to god its real, I know the guy

> mfw its 10 lines of strcmp() testing each possible case
okay, he could use an array of strings and loop over them. or maybe even do a binary search.
big deal.

It's true OP. I had to teach a guy the value of loops cause he too just wrote 10 lines of code. Luckily, he understood and vastly improved. In my opinion though, the class itself was very shitty. If I hadn't already known how to program before coming in I would've gotten lost on at least some bits.

you're doing God's work user.

update: I just listened to him on the phone asking someone if exit() returns from the calling function or exits the program.
why

>your doing god's work
>>>/leddit/
>>>/9fag/

>your
>misquoting you're
well done!

He's obviously new to programming.
Why are you making a big deal out if someone learning?the fuck is wrong with you?

>mfw purposely telling my classmates wrong coding etiquette to make myself look better by comparison

What was the exercise?

>mfw its 10 lines of strcmp() testing each possible case

What's particularly wrong with this?

It would make much more sense to just convert whatever string is input to all lowercase letters. That's what I did when I fucked with Java, anyway. Accounting for every single case use isn't only retarded, but it's futile. Even for a simple input like "Jessica," there are over 5,000 different upper-case and lower-case variations.

>128 is 5000
wew lad

the "computer science graduates can't program" meme is completely true

I didn't believe it until I started interviewing people. I didn't think it could be that bad.

What's the value of loops when the compiler ultimately unrolls them anyway?

What did you use to calculate that? Now that I'm dwelling on it, I'm pretty sure I accidentally checked for all variations of "Jessica" accounting for case letters and the letters being swapped around.
Still, let's say there's 128 variations. It would be much more time-efficient and less monotonous to just convert the string to all lowercase, if the string has to say a certain word. If the string doesn't have to say a certain word, then accounting for case makes no fucking sense anyway. Just display whatever the user typed in. Let their phone keyboards correct their spelling for them.

100% coverage is great senpai, you'll get paid six figures just for mentioning that in your interviews

Not all variables are static.

In static uses, it still saves time

what an idiot. he should just use a loop to check for even/odd

Console.Write("Enter a whole number...");
int userNumber = Convert.toInt32(Console.ReadLine());
while (true) {
int i = 0
if userNumber = i {
Console.WriteLine("Your number is even!");
}
else {
Console.WriteLine("Your number is odd!");
}
i += 2
}

Because cleaner code
If you have two ways of writing the same thing, and both will ultimately compile into the same shit, then you should opt for the more readable one.

The ultimate reason for creation of high level languages is TO WRITE LESS code. You can do anything in brainfuck, but do you want to?

1 bit for each character to store upper/lower case, 7 bits -> 2^7 = 128.

>if userNumber = i
Wut.

>when the compiler ultimately unrolls them anyway

JMPing to a previous line of code is not "unrolling"
It's basically goto'ing after an if statement

Google what unrolling is.
You too, it never unrolls the loop entirely.

trash

>convert whatever string is input to all lowercase
>Accounting for every single case

>case
I interpreted this differently, I assumed he meant 'case' as in valid possibilities.

himself
> everyone knows meme arrows are cruise control for cool

>Google what unrolling is.

do you think it makes you smart to use hard words
why cant u just explain like normal human being person

So... what's the "right" way to do this?

i%2==0

not the picture, the op.

Console.Write("Enter a whole number...");
int userNumber = Convert.toInt32(Console.ReadLine());

if ((userNumber % 2) == 0) {
Console.WriteLine("Your number is even!");
}
else {
Console.WriteLine("Your number is odd!");

depends what the fuck he wants to do
he could just lower case it and do 1 str cmp

you are an idiot, how can you be this stupid

lets say writing a shell that takes 10 possible commands.

To avoid frequent use of jumps compiler often repeats content of loops N times, N usually being powers of two. The tradeoff is a bigger program. When the number of times an action is need to be done is not a multiple of N, but rather N+some small M, it jumps to near end of the unrolled loop to execute M instructions first, then to the beginning of the loop(this way it can execute loop multiples of N times, like x*N+M). Depending on how complex the loop is, it can be twice as fast.

(userNumber % 2 == 0) ? printf("Even\n") : printf("Odd\n");

Do you take pride in writing unnecessarily obfuscated code? If I were your boss you'd be fired immediately.

>takes pride in not knowing ternary if operator

I hope your children are born with physical and metal disabilities.

if you're going that way, why not
printf((userNumber % 2) ? "Odd\n" : "Even\n");

it's fine for this kind of stuff, but for more complex stuff it gets hard. for example:
int median(int a, int b, int c) {
return (a

>i want to act like i know what im talking about

it's a single ternary

complain when someone does this

good point, but i would generalize it more
printf("Your number is %s \n", (userNumber % 2) ? "Odd" : "Even" );

Bait

On the actual CPU level, all loops are handled with gotos anyway.

>meme arrows
GETOUT NEWFAG REEEEEEEEEEEEE

Convert input to lowercase and use multiple if statements to check for matches. Ideally, the most common commands should be at the top of the if block.

>ternary operator is "unnecessary obfuscation"

Wewlad
WEEEEEWWWW

can you explain that
i know when you just have one ? : but when multiple i have no idea

You don't need braces for single statements.

just nest it the way you do an if statement
so if
` a ? b : c`
is
`if a then b else c`
then
`a ? b ? c : d : e`
is
`if a then ( if b then c else d) else e`

You don't, but it's good practice.

Thought code was backticks here, what's the markup?

Read the sticky n00b

public class Main {
public static void main(String[] args) {
System.out.println((new Scanner(System.in).nextInt()) % 2 == 0 ? "Even" : "Odd");
}
}

dont know c#, so here is a java one liner

Seriously, people are so uptight here

He probably just skimmed through the tutorials or books.

You guys missed the whole program:
Console.Write("Enter a whole number:");
Console.Write("Your number is "+ ((Convert.toInt32(Console.ReadLine())%2)==0?"even":"odd") + "!" );


i dont even know, is this shit java ?

Lololol

You don't need them, but you are just bad if you don't have them. Adhere to the style guide, please.

puts((usernumber % 2) ? "Odd" : "Even");

if you're going to print a string then a newline just use puts.

the code i got for this task so far

while True:
number = float(input("Enter the number you want to see if it is an even number: "))
if number == 1:
print("this is add odd number")
while number > 1:
number = number - 2
if number == 1:
print("this is an odd number")
if number == 0:
print("this is an even number")

Pic is C# right? I'd use a loop and test for the loop specific integer.

Side note: what language would you guys recommend for getting into a software engineering course?

>float(input(...))
is this written in GLSL? I don't remember that being in C++ and it's definitely not in C.

try modulo

It's Python.

Being better than average is not that hard and not being better than average is not such a big deal that you have to be a liar about it.

If you're a liar on top of being a moron, you should sell houses instead of work with computers.

Same here. Careful about how you use that word.

>What's the value of loops when the compiler ultimately unrolls them anyway?
that's why the call it -FUNroll-loops right?

>be me
>get a degree in Finance
>classes are not easy, not hard
>party all the time, fuck tons of girls and have a blast without too much studying
>pass all my classes, get my degree, get 70k starting at a firm
>mfw stemfags who spend all day studying to get their meme degree and make as much or less than me starting

The CS majors at my school are total cancer.

>yeah I failed first year calculus and algorithms but I passed the class on software development and I have side projects like this site I made for my sister's bf
>I'm not looking to be a computer scientist so it's okay that I code like a Pajeet

Then they bitch about every prof that tries to keep the class interesting by assigning nontrivial assignments you actually have to sit down and think about.

inb4 !(userNumber & 1)
inb4 compiler optimisation
inb4 compiler optimisation is a meme
inb4 who the fuck is moot

For fuck's sake guys, do you have PTSD from getting raped by a piece of code that spans over several lines? You have to make your code legible, customizable and expandable.

$strResultMessage['en'] = "The number is %1.";
$strOdd['en'] = "odd";
$strEven['en'] = "even";
$locale = "en";

if (userNumber % 2 == 0)
{
$strResult = $strEven[$locale];
}
else
{
$strResult = $strOdd[$locale];
}

$strMessage = strParse($strResultMessage[$locale],1,$strResult);
printf($strMessage);

Of coursr, strParse would have been declared earlier. I don't think I need to specify how it'd work.

Rofl everyone getting baited hard.

Also check'em.

bool evenNumber = false;
bool active = false;

do
{

Console.WriteLine("Enter in a number between 1 and 100");
int userNumber = Convert.ToInt32(Console.ReadLine());


for (int counter = 0; counter < 100; counter += 2)
{
if (counter == userNumber)
{
evenNumber = true;
break;
}

else
{
evenNumber = false;
}
}

if (evenNumber == true)
{
Console.WriteLine("Even number!");
}

else
{
Console.WriteLine("Odd number!");
}

Console.ReadLine();
}
while (active == false);

Is this any good?

...No?

yup its python.

make some adjustments.

number = float(input("Enter the number you want to see if it is an even number: "))
while number > 1:
number = number - 2
print("still processing..")
if number == 1 or number == -1:
print("this is an odd number")
if number == 0:
print("this is an even number")


i just cant figure out what to do if the number is a decimal number (floating point).

You should use the modulo operator instead of a for loop

It actually seems politically incorrect for professors to criticize students' code. This is why you get shit like this.

I'm a complete beginner, I'll need to look into that. Thanks!

>tfw fell for the CS meme and can't get a job because replaced by pajeet and friends in India

Instead of
if number == 1 or number == -1:
print("this is an odd number")
if number == 0:
print("this is an even number")
do:
if number == 0:
print("this is an even number")
else:
print("this is an odd number")

if num % 2 == 0:
print("your number is even")
else:
print("your number is odd")

OH the percentage thing, yeah I used that for the fizzbang example not long back.

that code is a joke, right?

I genuinely thought you were trolling. Tip: If your solution include cycling through a limited subset of possible inputs, it's terrible and there's a lot of better ones out there. Sorry, I gotta say it like it is.

The modulo operator gives you the remainder of a division. Hence, it will give 0 if dividing an even number by 2.

But that's easy. An approach like and is pretty much like coding the modulo operation yourself. It forces you to understand what you're doing instead of letting the compiler do it.

Just don't actually do it in a professional setting or you'll be made fun of.

>What's the value of functions when the compiler ultimately inlines them anyway?

>hardcoding the same substring twice.

That's 30 bytes of disk space you will never see again.

What is wrong with you guys? Compilers convert loops and functions into gotos. A compiler never unrolls recursive code.

Hey I appreciate the advice, genuine thanks!

>Compilers convert loops and functions into gotos
of course, but there is optimizations some compilers do which is what they are talking about.

My pleasure brosky!

That's really cool, I like the logic behind it.

ahah thanks man. I've just started out

bravo
but wasn't the OP's pic in Java? does it work in java?