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

COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
1st Edition
ISBN:9780357392676
Author:FREUND, Steven
Publisher:FREUND, Steven
Chapter9: Formula Auditing, Data Validation, And Complex Problem Solving
Section: Chapter Questions
Problem 5AYK
icon
Related questions
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 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 <stdio.h>
#include <stdlib.h>

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<length;i++){
depositAmount[i]=0;
}
int sumSum = displaySum(depositAmount, length);

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

switch(userChoice) {
case'G':
getNewDeposit(depositAmount, length, count);
break;
  
case 'S':
printf("Sum of all deposits:\n");
long int sum = displaySum(depositAmount, length);
printf("%ld", sum);
break;
  
case 'D':
printf("Deposits are displayed from highest to lowest deposit amount: \n");
sortedValues(depositAmount, length, count);
break;
  
case 'A':
printf("Average of all the deposits:\n");
displayAverage(sumSum, count);
break;
  
case 'L':
printf("Lowest deposit is displayed below:\n");
displayLowest(depositAmount, length, count);
break;
  
case 'Q':
printf("You are now exiting the program...\n");
break;
  
default:
printf("Invalid option. Please enter a valid option.\n");
  
}
printf("\nPress 1 to back to Main Menu: \n");
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:\n");
scanf("%d", &newDeposit);
  
if (newDeposit > 0){
  
depositAmount[i]=newDeposit;
i++;count++;
printf("New deposit made\n");
} else {
printf("\nDeposit amount not valid. Please deposit an amount greater than 0.0.\n");
}
}
// function to get sum of all deposit values
int displaySum(int depositAmount[], int length){
long int sum=0;
int i;
  
for (i=0;i<length;i++)
sum+=depositAmount[i];
  
return sum;
}
// function to get average funciton value
void displayAverage(int sumSum, int count){
long int avg = 0;
  
   avg = sumSum;
avg = avg/count;
  
   printf("%ld", avg);
  
}
// 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]);
}
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Hiring Problem
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage