I am solving ATM2 (Beginner) problem but my code is not further proceeding after taking inputs
The source code is as follows:-
#include <stdio.h>
int main()
{
int T;
scanf("%d",&T);
int N[T], K[T];
int numbers[T][100];
for (int i =0; i<T; i++)
{
scanf("%d %d",&N[i],&K[i]);
for (int k=0; k<N ; k++)
{
scanf("%d",&numbers[i][k]);
}
}
int money;
for (int z=0; z<T; z++)
{
money=K[z];
for (int j=0; j<N[z];j++)
{
if (numbers[z][j]==money)
{
printf("1");
money = money - numbers[z][j];
}
else if (numbers[z][j]<money)
{ printf("1");
money = money - numbers[z][j];
}
else if ( numbers[z][j]>money)
{
printf("0");
}
}
}
}
Please format your source code - use the “preformatted text” ( </> ) in the post editor
I actually can’t get this to compile:
janitlodha-ATM2.cpp: In function ‘int main()’:
janitlodha-ATM2.cpp:11:25: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
for (int k=0; k<N ; k++)
Edit:
Oh, I see - it’s a case of C being overly-permissive compared to C++ - gcc merely issues a warning.
Nevertheless, the warning is a crucially important one: try adding a printf("k: %d\n", k); on the line above scanf("%d",&numbers[i][k]); and running locally with the sample input: