#Need help on a simple problem
13 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
here's my code
#include <iostream>
int main() {
int x,y;
std::cin >> x >> y;
if (x > y) {
for (int i = 0; i < y; i++) {
if (i + x == y) {
std::cout << x << i;
}
}
}
else {
for (int i = 0;i < x; i++) {
if (i + y == x) {
std::cout << y << i;
}
}
}
}
it doesn't show any error but it doesn't give output either
the conditions will never be true ig
well, that's likely because your code isn't actually reaching a cout statement. Have you tried running it in your debugger?
if you do (x >= y) only then it might work
as consider x = 3, y = 3
the condition will be true and 3 will be printed
it has to be true at 1 point right?
no not if x>y or x < y
consider x = 2, y = 3.
the first if will not work the else block will be executed
inside the condition of that loop (i + y == x) will never be true as
0 + 3 == 2 can never be true. try doing y - i == x
👍