#is this readable enough?
99 messages · Page 1 of 1 (latest)
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
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
I agree with Levi, you should work on formatting the code better
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
@kind onyx is this your alt or something lol
same cursed coding style
nah
@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
cant use that also
we are limited in what we can use
wtf kind of acient crap is that
idfk lmao
like only compilers from the 1980 do that
its just an activitie i enrolled in thaat would get me BA by 19
ive talked to my teachers and they say that how u learn
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
fr we told them that in newer compilers its not a problem but still they wont listen
by any chance do you know what compiler you are using?
and the version?
but with some edits in it
cause I think this was like a warning in C(++) versions pre 1998 or something
we have the [-wall] [-pedantic] [-ansi] enabled
yeah that is good
no doubt XD
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
so u suggest that i would use switch instead of ifs and what?
like smthn that wouldnt give me warnings
wait lemme make an version of what I think would be clean
np take yr time
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
cant use functions:(
wtf is this for bullshit
im limited with what i can use
but thats like actively hurting you 
what a weird teacher
not allowing you to use function literally makes you and your code worse
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
Well, when you want to relearn it all the "right" way after you're done with these classes, come back and we'll give some resources.
actually the worst way to learn
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
I always find this weird with teaching you can't use Y cause you didn't get thought Y
just seems so counter productive to me
sounds like they don't want you to learn and just want you to follow the course
im all ears XD
well still didnt learn anything from my uni course i just know how to code in c cuz of c# which im learning in school
...not really
Those are completely different languages
ik but almost same structure with what ive seen so far
second year in school so not so much but know the basics 8)
not even close
tho if u are just doing the basics itll be sorta similar
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
That what i meant since in school we wont learn anything other than basics @flint radish