Hello, my task is to write a program for a user to input integer values and calculate the percentage of entered even numbers. The math part is kind of easy but then the task is to give the option to exit the input loop by typing "exit" not case sensitive or by just hitting enter. I am new to C programming and just started learning in school. Sorry if my question seems easy or dumb. But I have been at it for some time now and can't get it to work.
This is what I have so far:
Code:
int main()
{
int a, i, sum1=0, sum2=0, rel;
int d[100];
printf ("How many numbers will be entered\n");
scanf ("%d", &a);
printf ("Enter %d numbers (to exit program type - exit) \n", a);
for(i=0;i<a;i++)
{
if(1!=scanf ("%d", &d[i]))
{
if (strcmp(d[i], "exit") != 0)
break;
}
/* {
if (strcmp(d[i], "\n") != 0)
break;
} */
if (d[i]%2==0)
{
sum1=sum1+d[i];
}
else
{
sum2=sum2+d[i];
}
}
printf("\nElements in array are: ");
for(i=0; i<a; i++)
{
printf("%d, ",d[i]);
}
rel=sum1*100/(sum1+sum2);
printf ("\nRelative amount of evens in total amount is: %d percent\n", rel);
return 0;
}
Been looking though forums and tutorials and can't find the answer that would be the right one.
Thanks in advance for any help you can give me.