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

Rate my code /g/ :^)

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 54
Thread images: 6

File: code.png (2MB, 1079x376px) Image search: [Google]
code.png
2MB, 1079x376px
Rate my code /g/ :^)
>>
>>59043085
it's shit
>>
>>59043113
Why?
>>
>>59043085
>bottles and i are separate variables
Once you've fixed that, now make it start at a given value (instead of 99).
>>
>>59043085
I don't understand what your program does, what are you trying to achieve here?
>>
That's not how the song goes
>>
kinda goofy
>>
File: code2.png (1MB, 976x392px) Image search: [Google]
code2.png
1MB, 976x392px
>>59043227
How's this?
>>
>>59043254
By looking at whatever he's printing out, it's just the "99 Bottles of Beer" song.

Also yeah OP, >>59043380 is right, who the hell "shuffles around" bottles of beer?
>>
IT "PASS IT AROUND"YOU FUCKING MEMER
>>
>>59043085
if() {
}
//not
if()
{
}


cia nigger
>>
>>59043428
>>59043430
I was just trying to add a little personal spice to my script
>>
File: 1485298228962.gif (2MB, 270x138px) Image search: [Google]
1485298228962.gif
2MB, 270x138px
>>59043085
>using namespace std;
>std::cout
good one.
>>
>>59043421
>i=i
Just leave that part empty.

for(; i > 0; --i)
>>
>>59043455
Why?
>>
>>59043085
wont start each verse on an odd number? so you're skipping the even verses.
>>
File: 1486585864826.jpg (51KB, 600x600px) Image search: [Google]
1486585864826.jpg
51KB, 600x600px
>>59043085
pajeet/10
>>
>>59043421
Also, you don't need that s variable, just use a ternary operator.

(i == 1 ? "" : "s")
>>
what the fuck is this autistic poem?
>>
>>59043478
you are saying "I'm using the namespace std" so you don't have to write std::blah_di_blah, but you are writing it anyway. You just need cout with no std::

Also, that's fairly bad practice, to use a blanket "using namespace ...." statement, it defeats the entire purpose of having namespaces. If you want to know why, just ask.
>>
>>59043453
If the spice was homosexuality, ya fucking nailed it faggot.

Don't fuck with road trip songs, that's how you die.
>>
>>59043516
Sorry, I learned from learncpp.com :^)
>>
>>59043085
>using namespace std;
>std::cout
>std::

>bottles -= 1;
>not just using bottles--;

>using strings for single char
>using string library at all

>having separate ints for bottles and counting even though they are the same value

>wasting three lines on curly brackets even though conditions contain a single statement

>using iostream library when simply printf would suffice
>>
>>59043542
>not learncp.com
>>
>>59043549
This is how bloatware is made, right?
>>
>>59043469
What's the difference between --i and i--?
>>
>no space on both sides of "<<"s
D R O P P E D
>>
>>59043542
no worries, we all start somewhere. just keep working. You know how to compile successfully, yes?
>>
>>59043585
Prefix and postfix
It makes no difference in a for loop but necessary if your using it in conditionals or functions. A prefix subtracts before checking and a postfix checks and then subtracts. Consider it an order of operations
>>
>>59043585
i--; // take the value of i then decrement
--i; // decrement i then take the value
>>
>>59043604
I guess? I started by using codeblocks in Windows (shut up, I know, visual studio is too big of a download), but for this little loop I was just using nano and g++ via a Linux terminal because I thought it'd be fun.
>>
>>59043662
I hope the markdown works.
I'm drunk, but I modified the code a bit, it probably sucks.

```c++
#include <iostream>
#include <string>

using std::cout;
using std::string;

int main() {
string bottles = " bottles";
for (int i = 99; i > 0; i--) {
cout << i << bottles << " of beer on the wall, "
<< i << bottles << " of beer.\n";
if (i - 1 == 1)
bottles = " bottle";
else if ( i - 1 == 0)
bottles = " no more bottles";
cout << "You take one down, pass it around,"
<< i << bottles << " of beer on the wall.\n";
}
cout << std::endl; // May as well flush the stream.
return 0;
}
```
>>
>>59043085
why do people even use cout?
it's so ugly and messy
is there something wrong with printf?
>>
>>59043882
Python fag detected
>>
>>59043085
>old shit langs
>>
>>59043882

cout << bottles << "bottles of beer on the wall, " << bottles << "bottles" << " of beer on the wall"<<endl;

vs

printf("%d bottles of beer on the wall, %d bottles of beer on the wall\n" bottles);

>>59043975
it's C faggot
>>
>>59043984
You are literally retarded. Kill yourself, you dumb fucking shit stain.
>>
>>59044015
no u
>>
>>59044019
You deserve to be buried alive in a box full of spiders, you fucking subhuman sack of shit. Your mother should be stoned to death for not having you aborted, you worthless shit stain.
>>
>>59044019
Get raped and kill yourself you retarded fucking faggot sack of nigger shit with down syndrome.
>>
>>59043815
code tags bro (bb style)
>>
>>59043984
Both are shit. cout for overloading the bitwise shift and causing a large trend to change that operator into a stream operator, and printf for having to parse format strings.

God I hate how I work in c and c++ every day
>>
File: Capture.png (17KB, 1069x192px) Image search: [Google]
Capture.png
17KB, 1069x192px
>>59043085
The one and only way to do bottles of beer.
(I am not serious)
>>
>shuffle it around
THAT'S NOT HOW IT GOES RREEEEEEE
>>
senior cs/10
>>
>>59043085
wtf, one of the worst code samples I've seen... why not s = (bottles == 1) ? "" : "s"
>>
File: file.png (69KB, 952x575px) Image search: [Google]
file.png
69KB, 952x575px
>>59043085
Made an attempt as well ^^
>>
>>59043085
Weird code style.
>>
>>59043542
learncpp.com tells you to not use the namespace for no reason...
>>
>>59043085
>using std:: when he declared namespace std
>>
>>59043085
poop/shit
>>
>>59043085
>>59043542
>using the smiley with a carat nose
>>
>>59043085
>>59043421
Thanks for making me want to kill myself
>>
>>59044058
>>59044066
no u
Thread posts: 54
Thread images: 6


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.