Question: Hello! I just need help with some debugging! I will post my solution and assignment requirements below. I did post about this already, but I

Hello! I just need help with some debugging!

I will post my solution and assignment requirements below. I did post about this already, but I had trouble with the previous solution. As for my own solution, the code executes but not all the results I am getting are correct. I have trouble mostly with the calculations part. Please explain your steps to me and let me know what I am doing wrong! Thank you in advance.

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.

MY SOLUTION:

#include #include

void getNewDeposit(int depositAmount[], int length, int count); void displayAverage(int sumSum, 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 MAIN 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, length, 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: "); displayAverage(sumSum, count); 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 length, int count){ float newDeposit; long int i = 0; printf("Please enter an amount to deposit: "); scanf("%d", &newDeposit); if (newDeposit > 0){ depositAmount[i]=newDeposit; i++;count++; printf("New deposit made "); } else { printf(" Deposit amount not valid. Please deposit an amount greater than 0.0. "); } } // 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 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!