Question: ************************************************************************************* REPOSTING ********************************************************************************************* ASSIGNMENT REQUIREMENTS: Create menu driven program: ----utilizes switch ----utilizes 1D arrays -----utilizes preventative coding (ex: if the user's option is invalid, the

************************************************************************************* REPOSTING *********************************************************************************************

ASSIGNMENT REQUIREMENTS:

Create menu driven program:

----utilizes switch

----utilizes 1D arrays

-----utilizes preventative coding (ex: if the user's option is invalid, the code would not execute further, but ask the user to reenter a valid option)

----utilize call by reference / call by value (where appropriate)

---outcome should carry out all menu options

Example of menu:

*** BANKING MAIN MENU ***

[[G]et new deposit

[S]um of all deposits

[D]eposits will be displayed from highest to lowest deposit

[A]verage of all deposits

[L]owest deposit will be displayed

[Q]uit the program

Please write in C.

Hello,

I don't mean to come off rude or anything, but I have posted this two other times and am still having issues with my code. I am going to post the assignment requirements above and my solution below and I would prefer (if possible) to be able to keep all the functions that I have. If not possible, I would prefer the calculations go in the main function and not the prototype to keep it simpler. I am really want to understand what is going on so please provide explanation of your steps or what else I am doing wrong.

All help is appreciated so thank you in advance!!!

The problems with my solution code:

There is no result when selecting the Average or Deposit summary, not even a single number shows up.

The sum is not working as intended and displays one of the values that I input

The lowest option is also not working and displays only 0.

Exits after you choose Average but not for any other option (should just redirect to main menu)

MY SOLUTION:

#include #include

void getNewDeposit(int depositAmount[], int count); void displayLowest(int depositAmount[], int length, int count) ; void sortedValues(int depositAmount[], int length, int count); int displaySum(int depositAmount[], int length);

int main(){

int temp = 1; int count = 0; char userChoice;

long i; long int sum = 0;

int length = 100000; int depositAmount[100000]; for (i=0;i

while (temp == 1){ printf("*** BANKING MENU *** "); printf(" [G]et new deposit "); printf("[S]um of all deposits "); printf("[D]eposits will be displayed from highest to lowest deposit "); printf("[A]verage of all deposits "); printf("[L]owest deposit will be displayed "); printf("[Q]uit the program "); printf("Enter your choice: "); scanf(" %c", &userChoice);

switch(userChoice) { case'G': getNewDeposit(depositAmount, count); break; case 'S': printf("Sum of all deposits: "); long int sum = displaySum(depositAmount, length); printf("%ld", sum); break; case 'D': printf("Deposits are displayed from highest to lowest deposit amount: "); sortedValues(depositAmount, length, count); break; case 'A': printf("Average of all the deposits: "); long int avg = 0; avg = sumSum; avg = avg/count; printf("%ld", avg); break; case 'L': printf("Lowest deposit is displayed below: "); displayLowest(depositAmount, length, count); break; case 'Q': printf("You are now exiting the program... "); break; default: printf("Invalid option. Please enter a valid option. "); } printf(" Press 1 to back to Main Menu: "); scanf("%d", &temp); } return 0; }

// funciton to get new deposit void getNewDeposit(int depositAmount[], int count){ int newDeposit; int i; printf("Please enter an amount to deposit: "); scanf("%d", &newDeposit); if (newDeposit > 0) { depositAmount[i] = newDeposit; i++; count ++; printf("New deposit made. "); } else { printf("No previous deposit made, history not avaialble to view. "); } } // function to get sum of all deposit values int displaySum(int depositAmount[], int length){ long int sum=0; int i; for (i=0;i

// function to get lowest deposit value void displayLowest(int depositAmount[], int length, int count){ int temp=0; int i; int j; for (i = 0; i < count; i++) { for (j = i+1; j < count; j++) { if(depositAmount[i] < depositAmount[j]) { temp = depositAmount[i]; depositAmount[i] = depositAmount[j]; depositAmount[j] = temp; } } } printf("%d", depositAmount[count-1]); }

//function to get descending order of deposits void sortedValues(int depositAmount[], int length, int count){ int temp=0; int i; int j; for (i = 0; i < count; i++) { for (j = i+1; j < count; j++) { if(depositAmount[i] < depositAmount[j]) { temp = depositAmount[i]; depositAmount[i] = depositAmount[j]; depositAmount[j] = temp; } } } // printing the sorted deposits in descending order for (i = 0; i < count; i++) { printf("%d ", depositAmount[i]); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!