Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // Homework 2
  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.
  3.  
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. int RESULTS(int, int, int, int ); // Protoype for results
  8.  
  9. int main()
  10. {
  11. int even_sum=0, odd_sum=0, even_count=0, odd_count=0, number=0, counter=0;
  12. char name[10];
  13.  
  14. printf("Hello! Please enter your name. \n");
  15. scanf("%s", &name);
  16.  
  17. printf("%s, you may now input numbers. Input 0 to exit.\n", name);
  18. scanf("%d", &number);
  19.  
  20. while (number > 0)
  21. { scanf("%d", &number);
  22.  
  23. if (number % 2 == 0)
  24. {
  25. even_sum= even_sum + number;
  26.  
  27. even_count= even_count+1;
  28. }
  29.  
  30. else
  31. {
  32. odd_sum= odd_sum + number;
  33.  
  34. odd_count= odd_count+1;
  35. }
  36.  
  37. if (number == 0)
  38. {
  39. printf("%s, the numbers you printed are as follows:", name);
  40. 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);
  41. break;
  42. }
  43.  
  44. }
  45.  
  46. return 0;
  47. }
  48.  
  49.  
  50. int RESULTS(even_count , even_sum , odd_count , odd_sum) //Function prints the values from the loop.
  51. {
  52. //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);
  53.  
  54. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement