Answer the question
In order to leave comments, you need to log in
Why doesn't code (c) work?
Always prints the word vorona, even if the number is not in the range. Please help me find the error. I can't figure out what's wrong
#include <stdio.h>
void main()
{
printf("Enter the number in range of 1-99. \n");
int a, v;
scanf_s("%i", &a);
int m = a % 10;
if (((a>=11) && (a <= 14)) || (m=0) || ((m>=5) && (m<=9)))
{
v = 0;
}
else if ((m >= 2) && (m <= 4))
{
v = 1;
}
else if (m = 1)
{
v = 2;
}
else v=3;
switch (v)
{
case 0:printf("%i voron", a); break;
case 1:printf("%1 voroni", a); break;
case 2:printf("%i vorona", a); break;
case 3:printf("uncorrected"); break;
}
_getch();
return 0;
}
Answer the question
In order to leave comments, you need to log in
https://ru.wikipedia.org/wiki/Yoda_Terms
Already in two places.
Moreover, in C you don’t need to put brackets in difficult conditions, as in Pascal, it’s quite a ride ...
But no, you added unnecessary parentheses and drowned out the error.
Also what I don't like.
Instead of 0,1,2,3 it is better to use the MANY/FEW/ONE/UNKNOWN constants.
In case 1, the wildcard is badly ripped off the board.
If the condition on MANY is the most complex and is fulfilled according to the residual principle, why do we do it first? Better something like…
• 10…20 → MANY
• 1 → ONE
• 2…4 → FEW
• Else MANY
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question