What's wrong with this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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 ("}");} } }

31st Jul 2020, 4:28 AM
Pankaj Kumar Panda
Pankaj Kumar Panda - avatar
3 Answers
+ 2
You are having an extra '}' in the end.
31st Jul 2020, 4:36 AM
Lakshay Mittal
Lakshay Mittal - avatar
+ 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..
31st Jul 2020, 12:57 PM
Jayakrishna 🇮🇳
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.
31st Jul 2020, 1:22 PM
Pankaj Kumar Panda
Pankaj Kumar Panda - avatar