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

Here is pseudocode to go along: function prototypes go here const int ARRAY_SIZE

ID: 3715997 • Letter: H

Question

Here is pseudocode to go along:

function prototypes go here

const int ARRAY_SIZE = 20;

main()

//declare the array

int numberList[ARRAY_SIZE];

int count= 0; //how many elements are in the array

int choice;   

do

choice = displayMenu (this function will return the user's choice)

switch on choice

case 1

increment the count

if count<=20

call function to add a number to the list - pass it the array and count

else

display error message that array is too big

break

case 2

call function to display the list - pass it the array and count

case 3

call function to display the list backwards - pass it the array and count

case 4

call function to sum up the numbers in the list - pass it the array and count

case 5

call function to say "good bye"

default

handle incorrect choice (ie, choice not 1-4)

end switch

while (choice not equal to 5)

end main

Sample Program Running: https://screencast.com/t/CiUunhty4fhn

Please create a menu-driven program that offers the user a chance to play with a list of numbers 1. Add one number to the end of the list 2. Display the list 3. Display the list backwards 4. Display the sum of all the numbers in the list 5. Exit the Numbers List Game Here are the rules General Rules: When the program starts, the list is empty Keep the menu looping around until the user wishes to stop. All numbers must be positive integers. Allow no more than 20 numbers to be added to the list in any given run of the program. Don't allow the program to crash keep a counter. Display the list. Either put a space between each number or put one number per line so that it's easy to read. Make all of the output beautiful Menu Qption 3 Display the list backwards. Either put a space between each number or put one number per line so that it's easy to read. Make all of the output beautfur Menu Qption4 Add up all the numbers in the list and display that number ntinued here: Menu Ontion 4 Add up all the numbers in the list and display that number Programming Rules You must use an array to hold the list of numbers. That array must be declared in main) and then passed around to the various functions Your code must be divided into logical functions- use a separate function to implement each menu option. No global variables. Global constants are okay. All good programming practices should be in place

Explanation / Answer

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

const int ARRAY_SIZE = 20;

int displayMenu(){

  

int choice;

printf("Select one of the folllowing options ");

printf("(1) AddLIst ");

printf("(2) Display List ");

printf( "(3) Display Backwards List ");

printf( "(4) Display the sum of List ");

printf( "(5) quit the Program ");

printf("Input Selection ");

char c;

while(scanf("%d", &choice) != 1)

{

puts("That is not a number.");

scanf("%d", &choice);

while ((c = getchar()) != ' ' && c != EOF); // Flush stdin

}

  

//scanf("%d", &choice);

  

return (choice);

}

void addList(int numberList[], int count){

int number;

printf("Enter number to add to list ");

scanf("%d", &number);

numberList[count -1 ] = number;

}

void displayList(int numberList[], int count){

int i;

for(i = 0; i < count ; i++){

printf("%d: %d ", i, numberList[i]);

}

}

void displayBackwardsList(int numberList[], int count){

int i;

for(i = count-1; i >= 0 ; i--){

printf("%d: %d ", i, numberList[i]);

}

}

void displaySumList(int numberList[], int count){

int i;

int sum = 0;

for(i = 0; i < count ; i++){

sum += numberList[i];

} printf("sum of list is %d ", sum);

}

void displayGoodByeMessage(){

printf("Good Bye!! ");

  

}

int main(){

int numberList[ARRAY_SIZE];

int count= 0; //how many elements are in the array

int choice;  

do {

choice = displayMenu();

switch(choice){

case 1:

  

if( count<20){   

count++;

addList(numberList, count);

}

else{

printf("array is too big ");

}

break;

case 2:

displayList(numberList, count);

break;

case 3:

displayBackwardsList(numberList, count);

break;

case 4:

displaySumList(numberList, count);

break;

case 5:

displayGoodByeMessage();

break;

default:

printf(" Invalid Choice " );

}

}while(choice != 5);

return(0);

}