#"Golf-ing" Assignment because it is MASSIVE right now...

210 messages ยท Page 1 of 1 (latest)

severe sinewBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

celest sage
#

you can use some macros to reduce some characters

#

if that's allowed

loud stream
#

Loop.

dapper spoke
#

What is the assignment exactly?

dapper spoke
#

not very specific

#

can you send the instructions verbatim

regal granite
#

you have a lot of repetition insert/begin/replace/find, you could save characters by putting all your arguments in arrays and then looping through them

#

you could also precompute all the z[0].find("#"), they will be fixed

#

and if you don't need both <array> and <vector>, you can drop one include

dapper spoke
#

Can you send the .txt file?

#

of the provided file

#

lol, no you don't

#

hmm, strange

broken beacon
#

I think you could have all the "turtle doves", "french hens", etc stored in a vector, then loop in reverse and add the number in the loop

#

If you have fmt you could do "On the {} day of christmas my true love..."

#

Nested for loops should make it pretty easy

marsh fog
#

im trying to do a array loop but idk how i could call lines that come after others in the array part before others

#

cuz in my for loop, im thinking of incrementing a variable and outputting thhat many strings of the array

#

but array gets output from a b c for eg

#

i want c b a

#

but i want to add a string in place D next

#

not A

broken beacon
#
for (int i = 1; i < 13; i++) // day count
{
for (int j = i-1; j >= 0; j--)
{
printindex(j);
}
}
#

Smth like this? Idk

marsh fog
#

hmm

#

yeah

broken beacon
#

Iterate through the thing in reverse

#

Also since it's all fixed anyway, might as well hardcode them

marsh fog
#

from 12 down to 0?

#

if so, i tried it

#

i dont understand that

broken beacon
#

For the array printing?

marsh fog
#

yeah

broken beacon
#

What did you not understand

marsh fog
#

try adding what i told u originally, adding loops, how do i ncrement the day @ {} ?

broken beacon
#

With a loop

marsh fog
#

like how do i correct this {cout << x,num[0];

broken beacon
#

?

marsh fog
#

sorry im maiing youu so confused

#

making*

#

also yeah the code i sent has some errrors to fix but i want to fix this frist since you are here rn

dapper spoke
#

i would use 2 string variables

broken beacon
#

std::format(x, num[i])

#

Or fmt::format

marsh fog
#

cout << std::format(x, num[i]); ?

broken beacon
#

Yes. Include <format> and use c++20

dapper spoke
#

replace x with the text

dapper spoke
broken beacon
marsh fog
broken beacon
dapper spoke
marsh fog
dapper spoke
#

format is c++20 i believe

marsh fog
#

wow so my prof scuffed me?

dapper spoke
marsh fog
#

prof wants us to use this specifically

#

im sad

broken beacon
#

Oh then just use fmt::format

dapper spoke
broken beacon
#

Include the fmt header instead of <format>

dapper spoke
#

tbh your prof won't run it with the argument so probably shouldn't use it

broken beacon
#

fmt::print(blah, blah2) is shorter than std::cout<<std::format(blah,blah2) as well

marsh fog
marsh fog
#

what?

broken beacon
#

In your origibal post you have <fmt/format.h>

dapper spoke
marsh fog
#

and even got rid of all the includes accidentally

#

so i was confussed

#

but i added it back

broken beacon
marsh fog
#

and still erorr

broken beacon
#

Can you send the line where you used the fmt

marsh fog
#

    cout << fmt::format("\n\nOn the {} day of Christmas \nmy true love sent to me:", num[i]);

broken beacon
#

It looks like youre missing the fmt.c or whatever that's called

#

It should be compiled and linked

marsh fog
#

oh god

#

what is that now....

#

wait

#

one sec

#

nvm

#

i thought since im writing this code in a standard file, one that i created for myself, that if i copy paste the code into the file the prof provided, that perhaps it would run in his provided "template" cuz he may have added stuff from the libraries that we may have needed

broken beacon
#

It's a compiling thing

marsh fog
#

so compiler is dumb?

broken beacon
#

No

#

You have to add the fmt file to the compler flags

marsh fog
#

The fmt library is an awesome C++ library for printing and formatting text. I highly recommend using it in your projects.
For more information about this library and to read the documentation https://fmt.dev/latest/index.html

==== Awesome Links ====
๐Ÿ—ฃ Discord: https://discord.gg/XyhP8uYPTS
โœ๏ธ Github: https://github.com/TheBuilder-software
๐Ÿ’Ž Pa...

โ–ถ Play video
broken beacon
#

Uhhh i wouldnt trust that

#

Grab it here ^^

marsh fog
marsh fog
dapper spoke
#

Do the directions let you use 3rd party libraries?

#

:0

marsh fog
#

haha... idk

#

tbh he himself said:

dapper spoke
marsh fog
#

didnt read that

#

well more like

#

didnt know fmt was a didfferent library

dapper spoke
#

ive never used it

marsh fog
#

i see

#

now im lost on what to do yay

#

si there a slower way to do what we wanted to do?

dapper spoke
#

ya

marsh fog
#

hit me

#

i dont care anymore i give up

#

i'll just take the B

dapper spoke
#

str1 = "\n\nOn the ", str2 = " day of Christmas \nmy true love sent to me:";

#

in between put in a variable

#

for the num

#

num[i] yeah

#

probably simpliest way

marsh fog
#

k lemme try

#

my compiler is dying

#

heh

dapper spoke
#

wdym

marsh fog
#

well its lagging

#

but i think igot it tho

dapper spoke
#

nice

marsh fog
#

cant type in the code cuz its freezin up but yeah

#

um not at all

#

idk why its doing that

dapper spoke
#

it shouldn't lag lmao

marsh fog
#

ig this thing is built diff

#

it usually doesnt lag lol

#

the coding thing

#

pc never

dapper spoke
#

werid

marsh fog
#

oh btw, this is as small as it can get right?

#

i cant shorten ?

#

hmm.. when i try running this, it really struggles

dapper spoke
#

Yeah because you're accessing stuff outside the array

#

in the for loop

severe sinewBOT
#
Undefined Behavior

Undefined behavior occurs when you violate rules specified by the language. For example: Reading uninitialized memory, performing out-of-bounds memory access, signed integer overflow, and race conditions.

Example: Read Indeterminate Val.
int i; // default init,
       // indeterminate value
while(i < 10) {
    printf("%d\n", i++);
}
Example: Out-of-Bounds Access
int arr[10];
for(int i = 0; i < 20; i++) {
    arr[i] = i; // [i] out of
                // bounds
}
Consequences of UB

Compilers are not required to provide warnings or errors about UB. Often it is undetectable at compile-time. Performing actions which are UB can render your entire program's behavior undefined, leading to anything from crashing to summoning Eldritch Abominations.

See Also

Sanitizers can help identify UB. For more info, look into address sanitizer (ASan) and undefined behavior sanitizer (UBSan). See !howto asan

marsh fog
dapper spoke
#

How is it not a problem kekw

marsh fog
#

it doesnt feel like it to me...

#

so i just move everything into the for looop..?

#

except the array itself

dapper spoke
#

What?

#

why would you do that

dapper spoke
#

Look at the first for loop

#

also you understand that arrays start at 0 right

marsh fog
#

staring into its soul rn

dapper spoke
#

the for loop exits at 13

marsh fog
#

i fixed it just as u said 12

#

heheh

#

me samrt

#

smart

#

( i wish)

dapper spoke
#

now fix the other for loop

#

wait it might be correct

marsh fog
#

wait hold up

#

im missing one day

dapper spoke
#

Yeah, remove the -1

marsh fog
#

yay

#

it worked

dapper spoke
#

it's not 100% correct, make sure to compare the texts

marsh fog
#

hmm why was that there in the first place?

dapper spoke
marsh fog
#

yeah i know i saw

#

first day caant have "and a" in its output

dapper spoke
#

yeah, remove the and

marsh fog
#

ig its on me for not noticing

dapper spoke
#

true

cloud cliff
#

this is so embarassing man

severe sinewBOT
#

@marsh fog

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.

cloud cliff
#

@marsh fog just plain embarasing dawg

marsh fog
#

bruh what

cloud cliff
#

deleting your message too

marsh fog
#

fyi i didnt even use their codes

#

im deleting cuz idk if u copy

#

on my life

cloud cliff
#

LMAOOO

marsh fog
#

?

#

bruh what

#

@cloud cliff whyd u go quiet

#

i dont understand what makes u think this is embarassijg

cloud cliff
#

: )

marsh fog
#

@cloud cliff bro npc

#

its more embarassing seeing someone who clowns on another for no reason

#

the fact that u are also here in this server doesnt make u less embarassing than me @cloud cliff

#

i came for guidance... you for clowning?

#

tf?

#

the audicaty man

#

no responses?

#

@cloud cliff

#

stop hiding dawg

cloud cliff
#

u done talkin dawg?

marsh fog
#

finally replying

#

and you dipped again

#

@cloud cliff

marsh fog
#

your arguments are so strong wow

dapper spoke
#

Scroll up if you think he copied me? There's clearly a lot of discussion going on.

#

As well as the for loops are not similar to mine 8)

steel trellis
#

mfs arguing over code ๐Ÿ’€ ๐Ÿ’€