[Courses] [C] Beginner's Lesson Five: Decision and Control Statements

Morgon Kanter admin at surgo.net
Fri Oct 11 17:34:46 EST 2002


>#include <stdio.h>
>int main(void)
>{
>        char line[100];     /* line for data input */
>        int total;          /* running total of numbers */
>        int item;           /* next item to add to list */
>
>        total = 0;
>        while (1)
>        {
>                printf("Enter # to add\n");
>                printf("  or 0 to stop: ");
>                fgets(line, sizeof(line), stdin);
>                sscanf(line, "%d", &item);
>                if (item == 0)
>                        break;
>                total += item;
>                printf(Total: %d\n", total);
>        }
>        printf("Final total %d\n", total);
>        return (0);
>}

Um, what does the += operator do?




More information about the Courses mailing list