Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MUST BE WRITTEN IN C *****Hello, I just need help debugging my solution! I will post my solution, the output example, and what I am

MUST BE WRITTEN IN C

*****Hello, I just need help debugging my solution! I will post my solution, the output example, and what I am having issues with specifically below. There's a long list of requirements for the assignment, but to cut this short, the use of defined constants and pass by vals/refs are specific so please don't take these out.******

Issues with the code:

1. When recalling the Main Menu after the first time using it, it prints the Main Menu + options twice. (I'm supposed to use a do/while loop to repeat through the main menu and I think I am using it right???)

2. I am unsure if I wrote my 2D array correctly. When the user enters option 1, it should gather the next student's four ex@m scores. (Each row = to a student, however I think mine is not storing them accordingly)

SHOULD BE STORING LIKE THIS:

Index Ex@m1 Ex@m2 Ex@m3 Ex@m4

0. 90. 90. 80. 90

1. 30. 30. 30. 30

3. When displaying all the grades available, the display is really messy. (I want it to be cleaner and more aligned, but I am unsure of how to do this)

4. I am unsure if all my functions and calculations are all that exact. (I followed my notes and this is how they did it.)

5. After I compiled this I noticed part of my criteria is to error check for ex@m range (has to be from 0.0 to 100.0). (Can i just use a simple if/else loop for this?)

6. When printing the results for avgEx@m and avgStu theres a lot of decimal points after before reaching the percent sign. (Usually I would use set precision, but I am unsure if I can use this in C. So, how would i fix it so the output only display one number after the decimal point?)

Output Expectations:

image text in transcribed

My Solution: (HAD TO CHANGE THE A's IN EX*M to @ to be able to post)

#include #include

#define PAUSE system("pause") #define ROWS 1000 #define COLS 3 #define EX@M_MIN 0.0 #define EX@M_MAX 100.0

void getGrade(int grades[][COLS], int *effectiveSize); void displayGrades(int grades[][COLS], int effectiveSize); void displayAvgEx@m(int grades[][COLS], int effectiveSize); void displayAvgStu(int grades[][COLS], int effectiveSize);

int main(){ char userChoice; int grades[ROWS][COLS] = {0}; int effectiveSize = 0; do{ printf(" *** MAIN MENU ***"); printf(" 1. Add grades for next student"); printf(" 2. Display all grades"); printf(" 3. Show average by ex@m"); printf(" 4. Show average by student"); printf(" 5. Quit program"); printf(" "); printf("Enter your choice: "); scanf("%c", &userChoice); switch(userChoice){ case '1': getGrade(grades, &effectiveSize); break; case '2': displayGrades(grades, effectiveSize); break; case '3': displayAvgEx@m(grades, effectiveSize); break; case '4': displayAvgStu(grades, effectiveSize); break; case '5': printf("Exiting the program..."); break; defaut: printf("Invalid option. Please enter a valid option. "); break; } }while(userChoice != 5);

}

//function to get new grade value void getGrade(int grades[][COLS] , int *peffectiveSize){ int i; if (*peffectiveSize == ROWS){ printf("No available room for any additional students. Please notify your local tech support to add more."); } for (i = 0; i

void displayGrades(int grades[][COLS], int effectiveSize){ int i; int j;

if(effectiveSize == 0){ printf("You have not entered any previous grades. Please do this first."); } for (i = 0; i

void displayAvgEx@m(int grades[][COLS], int effectiveSize){ int total = 0; float examAverage = 0.0; int row; int cols; if(effectiveSize == 0){ printf("You have not entered any previous grades. Please do this first."); } for (cols = 0; cols

void displayAvgStu(int grades[][COLS], int effectiveSize){ int total = 0; float studentAverage = 0.0; int row; int cols; if(effectiveSize == 0){ printf("You have not entered any previous grades. Please do this first."); } for (row = 0; row

******* THANK YOU IN ADVANCE AND PLEASE STICK ONLY TO USING C ******************

MAIN MENU 1. Add grades for next student. 2. Display a77 grades. 3. Show average by Exam. 4. Show average by student. 5. Quit the program. Enter selection

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions