#is this readable enough?

99 messages · Page 1 of 1 (latest)

cloud rose
somber cradleBOT
#
Program Output
Menu: 
0. Exit 
1. Absolute subtraction
2. Increase modulo bitwise 
3. Play! 
4. Add diff game! 
5. Generate weird number 
Undefined choice, Exit? (Y,N)Menu: 
0. Exit 
1. Absolute subtraction
2. Increase modulo bitwise 
3. Play! 
4. Add diff game! 
5
pale arrow
#

honestly I would somewhat say no

#

it's insanely dense code

#

there is not a single enter in this code

#

and it's one huge ass function

#

pull some stuff int functions

#

throw menu choices in like a switch statement so it's actually readable what the options mean

#

int MenuChoice,num1,num2,AbsoluteDiff,PositiveNum,NewNum=0,RoundCounter=1,IntegerGuess,RightGuess111=0,RightGuess235=0,RightGuess999=0,score=0,ComputerGuess=5,UserGuess,LeftMostDigit,RightMostDigit,NumOfDigits,SumOfDigits=0,CounterOfDigitsInX=2,CounterOfDigits=0,sum2,DigitX,KCounter;

#

wtf?

#

just declare the variables as close to possible to their first usage

#

this is not okay

#

that is 288 characters long what is just actual insanity

#

take for example the char YesOrNo:

            char YesOrNo;
            if(scanf(" %c",&YesOrNo)==0)
                {
                printf("\n input error");
                return 1;
                }
            if(YesOrNo=='Y')
                {
                return 0;
                }
            else
                {
                printf("Menu: \n0. Exit \n1. Absolute subtraction\n2. Increase modulo bitwise \n3. Play! \n4. Add diff game! \n5. Generate weird number\n");
                if(scanf(" %d",&MenuChoice)==0)
                    {
                    printf("\n input error");
                    return 1;
                    }
                }
            }
#

just define it right there

#

this is the only place that uses it

#

limit the scope

#

your indenting is also insanely wack by pretty much all standards I know of

            if(scanf(" %d",&num1)==0)
                {
                printf("\ninput error");
                return 1;
                }

almost no one indents their code like this:

            if(scanf(" %d",&num1)==0)
            {
                printf("\ninput error");
                return 1;
            }

or:

            if(scanf(" %d",&num1)==0) {
                printf("\ninput error");
                return 1;
             }

are basically the 2 sane ways

#
            if(num1>0&&num2>0)
                printf("The absolute difference of %d and %d: |%d-%d|=%d \n",num1,num2,num1,num2,AbsoluteDiff);
            printf("Have a good day!");

give yourself some intenting room here, this is so easy to misread

#
KCounter=CounterOfDigitsInX%CounterOfDigits;/*calculating the k*/

this comment just adds unnececairy noise it's clear you are calculating k here so the comment is pointless, this is also the first and only use of KCounter so delcare the variable here instead of on the top. And give the text some room to breath as well

int KCounter = CounterOfDigitsInX % CounterOfDigits;
#

this is so much readable then that soup of characters before

#

honestly as for your original question your documentation isn't the issue here it's pretty much everything else

primal tulip
#

Breaking things out onto their own lines and adding extra blank lines goes a long long way

#

And instead of creating all the variables at once at the top of the program, try to create them close to where they're actually being used

fallow roost
#

@kind onyx is this your alt or something lol

fallow roost
#

same cursed coding style

kind onyx
#

nah

flint radish
#

jesus fucking christ

#

you need functions man

cloud rose
#

@primal tulip @pale arrow im familier with the declaration prob but i can di nothing because the compiler we are using in uni gives warning about declaring in the middle of the code and the deduct point for warnings

cloud rose
#

we are limited in what we can use

pale arrow
cloud rose
#

idfk lmao

pale arrow
#

like only compilers from the 1980 do that

cloud rose
#

its just an activitie i enrolled in thaat would get me BA by 19

cloud rose
pale arrow
#

no lol

#

it's basically the complete opposite :)

#

no to be rude but this is like an example I would use on how not to write readable code

#

what is fine cause you are learning

cloud rose
#

fr we told them that in newer compilers its not a problem but still they wont listen

pale arrow
#

by any chance do you know what compiler you are using?

cloud rose
#

1min

#

GNU GCC

pale arrow
#

and the version?

cloud rose
#

but with some edits in it

pale arrow
cloud rose
#

we have the [-wall] [-pedantic] [-ansi] enabled

pale arrow
#

yeah that is good

pale arrow
#

gcc --version

#

could you run that?

#

curious what version you are running

#

but lemme make a rough edit of what I think would be a good aproach

cloud rose
#

so u suggest that i would use switch instead of ifs and what?

#

like smthn that wouldnt give me warnings

pale arrow
#

wait lemme make an version of what I think would be clean

cloud rose
#

np take yr time

pale arrow
#

allright that took a bit

#

@cloud rose

#

I can't guarantee I didn't break anything but this is a rough mockup on how I would go about it

cloud rose
#

cant use functions:(

pale arrow
#

wtf is this for bullshit

cloud rose
#

im limited with what i can use

pale arrow
#

but thats like actively hurting you peepocry

#

what a weird teacher

#

not allowing you to use function literally makes you and your code worse

cloud rose
#

ik like we have learned func

#

but we are not allowed to use them

#

because the hm was given before we started learnin func

#

ik its just irrelevant and crazy but i cant do anything

#

&sry for the waste of yr time

pale arrow
#

Nah it's all good

#

It's the worst for you

primal tulip
flint radish
#

its funny how that happens

#

like if you cant use functions

#

how are u gonna learn how to actually program lmao

#

thats like the most basic component ever

pale arrow
#

just seems so counter productive to me

kind onyx
cloud rose
flint radish
#

...not really

primal tulip
flint radish
#

and just from the code they sent

#

i dont think they really learned it

cloud rose
cloud rose
flint radish
#

tho if u are just doing the basics itll be sorta similar

pale arrow
#

yup can concur, did C# once and could kinda struggle trough understanding it cause I could get the basics, it's definitly another language entirely

cloud rose