Advertisement
Ponnyou

Ordinals.c

Oct 15th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. /*
  3. *Bradley Felix, bfelix2019@my.fit.edu
  4. *CSE 1001, Section E2, Fall 2019
  5. *Project: oridnal.c
  6. */
  7. int main (void){
  8.    
  9.     //Introduction and input values
  10.     int i, a, sum = 0;
  11.    
  12.     printf("Welcome to Oridnal numbers!\n");
  13.     printf("Enter a value between 0 and 65535 (negative value to quit): ");
  14.     scanf("%d", &a);
  15.    
  16.     //Checking to see if input is outside range
  17.     while (a > 65535){
  18.         printf("Input not allowed. Try again.\n");
  19.         printf("Enter a value between 0 and 65535 (negative value to quit): ");
  20.         scanf(" %d", &a);
  21.     }
  22.    
  23.     //Start the loop
  24.     while (a >= 0){
  25.         while (a > 65535){
  26.             printf("Input is not allowed. Try again.\n");
  27.             printf("Enter a value between 0 and 65535 (negative value to quit): ");
  28.             scanf(" %d", &a);
  29.         }
  30.         for (i = 0; i <= a; i++){
  31.             printf("%d Value\n", i);
  32.             sum += i;
  33.         }
  34.         printf("Enter a value between 0 and 65535 (negative value to quit): ");
  35.         scanf("%d", &a);
  36.     }
  37.    
  38.     printf("The sum of all your entered numbers is %d\n", sum);
  39.     printf("Goodbye! Thanks for playing!");
  40.    
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement