// Demonstrating the use of a while loop with a sentinel // condition. // Week 2, Lecture 3 // Problem: I want to read in some numbers until a // negative number has been // entered, and sum up all the positive numbers. // Let's think through the steps to solve this! /* 1. Keep scanning in numbers - scan in a number 2. Check if that number is negative - if negative - I would stop scanning - else I would keep scanning and add it to the total */ #include int main (void){ int number = 1; int sum = 0; while (number > 0) { scanf("%d", &number); //if (number > 0) { sum = sum + number; //} } printf("Sum = %d\n", sum); return 0; }