Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Homework 2
- // Program requests integers from user until they enter 0 to quit. Program tests each entry to see if number is even or odd, counts up number of even and odd entries, then totals them separately.
- #include <stdio.h>
- #include <stdlib.h>
- int RESULTS(int, int, int, int ); // Protoype for results
- int main()
- {
- int even_sum=0, odd_sum=0, even_count=0, odd_count=0, number=0, counter=0;
- char name[10];
- printf("Hello! Please enter your name. \n");
- scanf("%s", &name);
- printf("%s, you may now input numbers. Input 0 to exit.\n", name);
- scanf("%d", &number);
- while (number > 0)
- { scanf("%d", &number);
- if (number % 2 == 0)
- {
- even_sum= even_sum + number;
- even_count= even_count+1;
- }
- else
- {
- odd_sum= odd_sum + number;
- odd_count= odd_count+1;
- }
- if (number == 0)
- {
- printf("%s, the numbers you printed are as follows:", name);
- printf("%d even numbers with a total value of %d and %d odd numbers with a total value of %d.\n", even_count , even_sum , odd_count , odd_sum);
- break;
- }
- }
- return 0;
- }
- int RESULTS(even_count , even_sum , odd_count , odd_sum) //Function prints the values from the loop.
- {
- //printf("%d even numbers with a total value of %d and %d odd numbers with a total value of %d.\n", even_count , even_sum , odd_count , odd_sum);
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement