Hi! I would like to ask you, how to compare each element of array with another,defined ? I have tried this,but didn't work.
Code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void bill()
{
float bill;
printf("Enter value of your bill: ");
scanf("%f",&bill);
while (bill<0 || bill>10000)
{
printf("Wrong input\n");
break;
}
}
int main()
{
char p[1000];
char val[1000];
int length = 0;
char* itr;
char notes[]={100,50,20,10,5,2,1,0.50,0.20,0.10,0.05,0.02,0.01};
bill();
while(getchar()!='\n');
fgets(p,sizeof(p),stdin);
itr = strtok(p, " ");
while(itr!=NULL)
{
val[length]=atof(itr);
itr = strtok(NULL, " ");
length ++;
val[length]= val[length];
}
itr = strtok(p, " \n");
for(int k=0;notes[k];k++) //comparing
{
for(int i=0;i<length;i++)
{
if(p[i]!=notes[k])
{
printf("%c is invalid\n",p[i]);
}
} }
return 0;
}
Thanks for help !