Uitdaging: Else-instructie
else.h
12345678if (condition) { // Code to be executed if the condition is true } else { // Code to be executed if the condition is false }
main.cpp
12345678910111213#include <iostream> int main() { int x = 5; if (x > 10) { std::cout << "X is greater than 10" << std::endl; } std::cout << "X is not greater than 10" << std::endl; }
main.cpp
123456789101112131415#include <iostream> int main() { int x = 5; if (x > 10) { std::cout << "X is greater than 10" << std::endl; } else { std::cout << "X is not greater than 10" << std::endl; } }
Opmerking
Taak
Swipe to start coding
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 1. Hoofdstuk 4
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Suggested prompts:
Can you show me an example of how the if-else statement should be structured?
What happens if I add more conditions, like using else if?
Can you explain why the second std::cout was always executed before the fix?
Geweldig!
Completion tarief verbeterd naar 7.69
Uitdaging: Else-instructie
Veeg om het menu te tonen
else.h
12345678if (condition) { // Code to be executed if the condition is true } else { // Code to be executed if the condition is false }
main.cpp
12345678910111213#include <iostream> int main() { int x = 5; if (x > 10) { std::cout << "X is greater than 10" << std::endl; } std::cout << "X is not greater than 10" << std::endl; }
main.cpp
123456789101112131415#include <iostream> int main() { int x = 5; if (x > 10) { std::cout << "X is greater than 10" << std::endl; } else { std::cout << "X is not greater than 10" << std::endl; } }
Opmerking
Taak
Swipe to start coding
Oplossing
Was alles duidelijk?
Bedankt voor je feedback!
Sectie 1. Hoofdstuk 4
single