T
Tiny Tim
Hope someone can help me to overcome this problem.
Case 1 is working perfectly working with one number entry.
Case 2 is the problem when I tried with 2 numbers entry.
Case 1.
#include <stdio.h>
int main ()
{
int a,i;
for (i=1;i<=3;i++)
{
scanf ("%d",&a);
printf ("%d\n",a);
}
return 0;
}
/* Result
5
5
15
15
234
234
Press any key to continue
*/
As the result shows, I enter 5 and computer prints 5,
enter 15 and computer prints 15 , 234 and prints 234. No problem with this.
The problem comes when I deal with 2 numbers, a and b.
Case 2
#include <stdio.h>
int main ()
{
int a,b,i;
for (i=1;i<=3;i++)
{
scanf ("%d,%d",&a,&b);
printf ("%d,%d\n",a,b);
}
return 0;
}
/* Result
1 2
1,-858993460
2,-858993460
3 4
3,-858993460
Press any key to continue
*/
As you can see from the above result, when I enter 1 2, I get weird result. I suspect the computer is printing "space" and "enter key".
How do I overcome this problem?
Thanks
Khoon.
Case 1 is working perfectly working with one number entry.
Case 2 is the problem when I tried with 2 numbers entry.
Case 1.
#include <stdio.h>
int main ()
{
int a,i;
for (i=1;i<=3;i++)
{
scanf ("%d",&a);
printf ("%d\n",a);
}
return 0;
}
/* Result
5
5
15
15
234
234
Press any key to continue
*/
As the result shows, I enter 5 and computer prints 5,
enter 15 and computer prints 15 , 234 and prints 234. No problem with this.
The problem comes when I deal with 2 numbers, a and b.
Case 2
#include <stdio.h>
int main ()
{
int a,b,i;
for (i=1;i<=3;i++)
{
scanf ("%d,%d",&a,&b);
printf ("%d,%d\n",a,b);
}
return 0;
}
/* Result
1 2
1,-858993460
2,-858993460
3 4
3,-858993460
Press any key to continue
*/
As you can see from the above result, when I enter 1 2, I get weird result. I suspect the computer is printing "space" and "enter key".
How do I overcome this problem?
Thanks
Khoon.