Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C programming Capturing of Random Numeric Inputs Process (assigned to Programmer

ID: 3691805 • Letter: C

Question

C programming

Capturing of Random Numeric Inputs Process (assigned to Programmer B):

For each of the “playing with numbers” selections, a user must enter in a collection of numbers that will then be worked upon by each of the possible processing selections. The user is allowed to enter from 1 to 10 numeric values and should be prompted to do so:

Please enter the quantity of numbers you wish to enter. Enter a number between 1 and 10:

If a numeric that is less than 1 or greater than 10 is entered, the user must be notified of the error and the same question prompt should be displayed (this should continue until the users enter one of the correct selections):

Invalid selection! Please Try Again.

Please enter the quantity of numbers you wish to enter. Enter a number between 1 and 10:

After the user selects the number of values to entered, the program should then begin collection each individual input value till the number requested is reached. On each prompt for a numeric input, the order of the number input should be displayed (red numbers represent user input values):

Please enter number 1: 5

Please enter number 2: 2

Please enter number 3: -59

Please enter number 4: 1547

Please enter number 5: 5487

Constraint: The numbers entered by a user must be stored in an array structure. Any collection of values entered by a user must be passed from one process to another via this (or another) array structure. Failure to use arrays for this assignment will have an extremely negative impact to your grade for this assessment.

After the user enters in all of the numeric selections, the process should then continue to execute the processing selection made by the user.

Explanation / Answer

#include <stdio.h>

void playWithLetters(char* input);
void playWithNumbers();

int main() {

   char input[] = "The quick brown fox jumps over the lazy dog.";
   int choice = -1;
   while (choice < 0 || choice > 2) {
       printf(
               "Playing with Numbers or Letters ==-- Would you like to play with numbers or letters? Enter 1 for numbers and 2 for letters (0 to exit)");
       scanf("%d", &choice);
       if (choice < 0 || choice > 2) {
           printf("Invalid selection! Please Try Again. ");
       } else if (choice == 0) {
           return 0;
       } else if (choice == 1) {
           playWithNumbers();
       } else {
           playWithLetters(input);
       }
       choice = -1;
   }
   return 0;
}

/**
* This function will be called for Letters only.
*/
void playWithLetters(char* input) {
   int choice = -1;
   char inputChar;
   while (choice < 0 || choice > 2) {
       printf(
               "What would you like to do? Find more than one occurrence of a character Find character occurrence that has a vowel before it. Enter 1 or 2. (0 to return to main selection) ");
       scanf("%d", &choice);
       if (choice < 0 || choice > 2) {
           printf("Invalid selection! Please Try Again. ");
       } else if (choice == 0) {
           return;
       } else {
           while (!((inputChar >= 'a' && inputChar <= 'z')
                   || (inputChar >= 'A' && inputChar <= 'Z'))) {
               printf(
                       "Please enter an alphabetic character to work with. Enter any upper or lower case character: ");
               scanf("%c", &inputChar);
           }
           int count = 0;
           int i = 0;
           if (choice == 1) {
               /**
               * Here we are traversing complete sentence to check the occurrences of input character.
               */
               for (i = 0; input[i] != ''; i++) {
                   if (input[i] == inputChar) {
                       count++;
                   }
               }
           } else {
               /**
               * Here we are checking if before character is vowel or not if it is we are incrementing count.
               */
               for (i = 1; input[i] != ''; i++) {
                   if (input[i - 1] == 'a' || input[i - 1] == 'e'
                           || input[i - 1] == 'i' || input[i - 1] == 'o'
                           || input[i - 1] == 'u' || input[i - 1] == 'A'
                           || input[i - 1] == 'E' || input[i - 1] == 'I'
                           || input[i - 1] == 'O' || input[i - 1] == 'U') {
                       if (inputChar == input[i]) {
                           count++;
                       }
                   }
               }
           }
           printf("Total occurrences %d", count);
       }
   }
}

/**
* This function will be called for Numbers.
*/
void playWithNumbers() {
   int choice = -1;
   int tempArr[10000];
   int numCount = 0;
   int finished = 0;
   int i = 0;
   while (finished == 0) {
       finished = 1;
       printf(
               "Please enter the quantity of numbers you wish to enter. Enter a number between 1 and 10:");
       scanf("%d", &numCount);
       int temp = 0;
       for (i = 0; i < numCount; i++) {
           printf("Please enter number %d : ", (i + 1));
           scanf("%d", &temp);
           if (temp < 0 || temp > 10) {
               break;
           }
           tempArr[i] = temp;
       }
       if (finished == 0) {
           continue;
       }
   }
   while (choice < 0 || choice > 2) {
       printf(" == Playing with Numbers ==-- What would you like to do? ");
       printf("Add 2nd and 3rd numbers of collection entered ");
       printf("Average of Numbers divisible by 3 of collection entered ");
       printf(
               "Multiplication of every 1st and 2nd numbers of collection entered ");
       printf(
               "Resort the collection entered by sets of three Enter 1, 2, 3, or 4 (0 to return to main selection): ");
       scanf("%d", &choice);
       if (choice < 0 || choice > 4) {
           printf("Invalid selection! Please Try Again. ");
       } else if (choice == 0) {
           return;
       } else {
           if (choice == 1) {
               printf("%d ", (tempArr[1] * tempArr[2]));
           } else if (choice == 2) {
               int sum = 0;
               int count = 0;
               for (i = 0; i < numCount; i++) {
                   if (tempArr[i] % 3 == 0) {
                       sum += tempArr[i];
                       count++;
                   }
               }
               printf("%d ", (count != 0 ? (sum / count) : 0));
           } else if (choice == 3) {
               printf("%d ", (tempArr[0] * tempArr[1]));
           } else if (choice == 4) {

           }
           choice = 0;
       }
   }
}

I didn't get the 4th option in numbers.