New course! Every coder should learn Generative AI!
Try a free lesson0
What's wrong with this code?
#include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); if(a < b) { printf ("Here is your Dictionary: \n{\n"); for (int i=a, x=0; i<=b, x<=b-a; i++, x++) { printf ("'index %d': %d,\n",x, i); } printf ("}"); } else { printf("Here is your Dictionary: \n{\n"); for(int i=a, x=0; i>=b, x <= a-b; i--, x++) { printf ("'index %d': %d,\n",x, i); } printf ("}");} } }
3 Answers
+ 2
You are having an extra '}' in the end.
+ 1
In addition to, :
You have two conditions instead of one..
i<=b, x<= b-a ;
It should be single condition..
Use logical && or || depends on need...
Like i<=b || x<=b-a
Same in else part...
Edit:
Pankaj Kumar Panda
then you can remove 1st condition in loop. It removes the warnings.... And No use of those..
0
No Jaykrishna. The problem is not that. I was putting an extra curly bracket at the end. Thanks to Lakshya Mital, the problem is solved now.