If statement not working | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

If statement not working

Hi, I've been trying to learn c++ for the past few days, today I wanted to try my first challenge named "Easter Egg" on the app. But the code that I have written isn't working. What did i do wrong? I don't understand #include <iostream> using namespace std; int main() { int egg=60, b=40, c=20; int i = b+c; if (i == egg){ cout << "Candy Time"; } else { cout << "Keep Hunting"; } return 0; }

16th Jan 2024, 7:56 AM
Reda Abdoun Ribeiro
Reda Abdoun Ribeiro - avatar
4 Antworten
+ 5
Your if statement is working fine. In the code coach challenges you have to write code that takes dynamic input, rather than hard-coding the values. Because there are multiple tests and each of them uses different values. Use the cin statement for your input variables.
16th Jan 2024, 8:20 AM
Tibor Santa
Tibor Santa - avatar
+ 4
Though I am unable to view the Pro Code Coach task, I am guessing that it requires your program to take input from the console. Usually Code Coach runs a number of tests on your program, supplying different input values through console input, and then it compares the output with expected values. Also be certain the output matches exactly what the task says. Capitalization and punctuation must match.
16th Jan 2024, 8:22 AM
Brian
Brian - avatar
+ 1
Reda, glad you got it resolved. Sololearn needs to work on clarifying that aspect of Code Coach. Similar questions appear pretty frequently here in Q&A.
16th Jan 2024, 8:56 AM
Brian
Brian - avatar
0
Thanks it was just that, I feel stupid
16th Jan 2024, 8:28 AM
Reda Abdoun Ribeiro
Reda Abdoun Ribeiro - avatar