Hello guys, I have a question about an If statement homework assignment. It is simple code designed to calculate the sum of 10 integers from stdin, and to printf the sum is over 100 or the sum is negative. Why is it when I input a letter instead of a number, the code can successfully run but with a crazy sum? Code located below, thanks for any help you can provide.
Code:
- #include <stdio.h>
- int main ()
- {
- /* variable definition: */
- int value1,value2,value3,value4,value5,value6,value7,value8,value9,value10,sum;
- /* Initialize sum */
- sum = 0;
- printf("Enter an Integer for value1\n");
- scanf("%d", &value1);
- printf("Enter an Integer for value2\n");
- scanf("%d", &value2);
- printf("Enter an Integer for value3\n");
- scanf("%d", &value3);
- printf("Enter an Integer for value4\n");
- scanf("%d", &value4);
- printf("Enter an Integer for value5\n");
- scanf("%d", &value5);
- printf("Enter an Integer for value6\n");
- scanf("%d", &value6);
- printf("Enter an Integer for value7\n");
- scanf("%d", &value7);
- printf("Enter an Integer for value8\n");
- scanf("%d", &value8);
- printf("Enter an Integer for value9\n");
- scanf("%d", &value9);
- printf("Enter an Integer for value10\n");
- scanf("%d", &value10);
- sum = value1 + value2 + value3 + value4 + value5 + value6 + value7 + value8 + value9 + value10;
- printf("Sum is %d\n " , sum );
- if (sum >100)
- printf("Sum is over 100\n");
- if (sum <0)
- printf("Sum is a negative value");
- return 0}
- }