ERROR (Logical) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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; }

5th Jan 2021, 7:36 AM
H. Ahmadian
H. Ahmadian - avatar
15 Answers
+ 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
6th Jan 2021, 6:41 AM
H. Ahmadian
H. Ahmadian - avatar
+ 2
Makar Mikhalchenko Nope! It seems No YES!!! It now Works 🤟 https://code.sololearn.com/c2lpTTPHrE2N/?ref=app
5th Jan 2021, 7:51 AM
H. Ahmadian
H. Ahmadian - avatar
+ 1
Did it work?
5th Jan 2021, 7:49 AM
Makar Mikhalchenko
Makar Mikhalchenko - avatar
+ 1
JaScript Do you have any Idea for C!? Edit this Code to Work!?
5th Jan 2021, 9:10 AM
H. Ahmadian
H. Ahmadian - avatar
+ 1
It works. Congratulation. It helps for complex dependency if you write on paper a truth table and then realize that in the code.
6th Jan 2021, 8:45 AM
JaScript
JaScript - avatar
+ 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.
6th Jan 2021, 9:02 AM
JaScript
JaScript - avatar
0
Did you test it first on SL Playground and seehow it works and then tried to solve of the problems?
5th Jan 2021, 8:31 AM
JaScript
JaScript - avatar
0
JaScript Yeah, I did; it output wrong for some inputs
5th Jan 2021, 8:33 AM
H. Ahmadian
H. Ahmadian - avatar
0
The algorithm will be as follows: t = input().replace("x", "") print("ALARM" if "$T" in t or "T
quot; in t else "quiet")
5th Jan 2021, 8:42 AM
JaScript
JaScript - avatar
0
JaScript My Code is C, not JavaScript!!! Dear friend 🤷 JavaScript have many capabilities to facilitate programming, C doesn't
5th Jan 2021, 9:04 AM
H. Ahmadian
H. Ahmadian - avatar
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.
5th Jan 2021, 10:07 AM
JaScript
JaScript - avatar
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
5th Jan 2021, 11:26 AM
JaScript
JaScript - avatar
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 🙏
6th Jan 2021, 12:13 AM
H. Ahmadian
H. Ahmadian - avatar
0
JaScript PS. C is the only programming language i ever worked with; not Professional of course! I'm not a Computer Science Graduate, so pardon me if i couldn't distinguish Python code from JavaScript
6th Jan 2021, 12:25 AM
H. Ahmadian
H. Ahmadian - avatar
7th Jan 2021, 4:18 AM
super entertainment DHMAKA
super entertainment DHMAKA - avatar