+ 4
ERROR (Logical)
I'm trying to Solve Challenge (Security) of Code Coach, why this Code can't produce desired output!!? I want Your help please 💓 int Casino_Security (char* casino) { int i = 0; int j = 0; while (*(casino + i)) { if(casino[i] == 'T' || casino[i] == '
#x27;) for(j=i+1; j<=strlen(casino) || casino[j] == 'G'; j++) if(casino[j] == 'T' || casino[j] == '#x27;) if(casino[i] != casino[j]) return 0; i++; } return 1; }15 odpowiedzi
+ 4
JaScript Hey my Friend!
Finally i found a way how to check both 'T' and '#x27; using 1 if statement; the way I wanted from first.
I changed the continuation condition of for loop and this is how function Casino_Security should be:
int Casino_Security (char* casino)
{
int i = 0;
int j = 0;
while (*(casino + i))
{
if(casino[i] == 'T' || casino[i] == '#x27;)
for(j=i+1; j<=strlen(casino) && casino[j] != 'G'; j++)
if(casino[j] == 'T' || casino[j] == '#x27;)
if(casino[i] != casino[j])
return 0;
i++;
}
return 1;
}
https://code.sololearn.com/c2lpTTPHrE2N/?ref=app
+ 2
Makar Mikhalchenko
Nope! It seems No
YES!!! It now Works 🤟
https://code.sololearn.com/c2lpTTPHrE2N/?ref=app
+ 1
Did it work?
+ 1
JaScript
Do you have any Idea for C!?
Edit this Code to Work!?
+ 1
It works. Congratulation.
It helps for complex dependency if you write on paper a truth table and then realize that in the code.
+ 1
I was lazy and just quickly converted my proven algorithm into code. In programs there are usually many ways that lead to the solution.
0
Did you test it first on SL Playground and seehow it works and then tried to solve of the problems?
0
JaScript
Yeah, I did; it output wrong for some inputs
0
The algorithm will be as follows:
t = input().replace("x", "")
print("ALARM" if "$T" in t or "Tquot; in t else "quiet")
0
JaScript My Code is C, not JavaScript!!! Dear friend 🤷
JavaScript have many capabilities to facilitate programming, C doesn't
0
This is in Python coded.
Of course I could it write in C, but it will be no help which make sense for you.
You have to code with structure. Divide the project on small steps and solve them. And this step by step with testing of each step.
You should make first a skizze of algorithm and test if it works with the task description.
Can you see from my code how the algorithm works and how easy is it.
0
If you want to see H. Ahmadian my above mentioned logical algorithm implemented in this C code:
https://code.sololearn.com/cxlIkutpA1Qf/?ref=app
0
JaScript
You broken the outer if statement within while loop of Casino_Security in to 2 sperate if statements and indeed you checked the '#x27; and 'T' separately, the idea that i wanted to refuse from first because I want to check both cases ($ and T) with 1 if statement.
Anyway thanks for your attention, yet if you have any idea to solve it in the way i want, let me know please; I'll be Grateful 🙏