Как мне отладить эту программу?
У меня есть проблема с очисткой данных в программе. Мне действительно нужна помощь, чтобы починить его. Программа зависает после перепросмотра где пользователю предлагается ввести имя другого студента и рассчитать оценки
Что я уже пробовал:
/ ZakAttack.cpp--A program for calculating student grades and // displaying the overall GPA // Shaheen Fathima Abdul Jamal Nazar, CISP 360 // Instructor: Professor Fowler // Date: 04/27/2018 #include <iomanip> #include <iostream> #include <limits> #include <string> using namespace std; // Variable Declarations string stName; int scores[50]; int *ptr = scores; int count = 0; // Function Prototypes void results(); void gradeAdd(); void mainMenu(); int getUserChoice(); void mainEvent(); int main() { // Program Greeting cout << " Hi! Welcome to the Zak Attack Program!\n" << endl; cout << " This program calculates the grades for a\n" << endl; cout << " specific number of quizzes taken by a student.\n" << endl; cout << " It also displays the overall grades along with\n" << endl; cout << " the letters (A-F) based on the scores attained by the student! " << endl; cout << endl; //Specification 2- Prompt for user to enter both first and last name cout << " Enter the name of the student (First and Last): "; getline(cin, stName); cout << endl; mainEvent(); return 0; } void mainEvent() { int userInput; bool task = true; do { mainMenu(); cout << "\nEnter your choice: "; userInput = getUserChoice(); if (userInput == 1) { gradeAdd(); } else if (userInput == 2) { results(); break; } else if (userInput == 3) { task = false; } } while (task == true); } void results() { // variables to be used int tem, sNum, rNum, pNum; bool swapNum; int scCopy[50]; int *ptrCopy = scCopy; int lowScore[15]; int *ptrLow = lowScore; double gpAvg = 0; char rChoice; cout << " Name of Student: " << stName << endl; // Copying scores[] to scCopy[] array for (int i = 0; i < count; i++) { *(ptrCopy + i) = *(ptr + i); } //Feature 6- Bubble Sort Array Copy do { swapNum = false; for (int j = 0; j < count; j++) { if (*(ptrCopy + j) > *(ptrCopy + (j + 1))) { tem = *(ptrCopy + j); *(ptrCopy + j) = *(ptrCopy + (j + 1)); *(ptrCopy + (j + 1)) = tem; swapNum = true; } } } while (swapNum); sNum = (count * 0.3); rNum = count; pNum = sNum; //Feature 7- Copying the lowest 30% to low[] and //Convert any copied out grades to 0 in scCopy[] for (int i = 0; i < sNum; i++) { *(ptrLow + i) = *(ptrCopy + i); *(ptrCopy + i) = 0; pNum--; } //Specification 3- Range test the input data for the grades //Display the grades as letters and overall GPA for (int i = 0; i < count; i++) { if (*(ptrCopy + i) >= 94) { cout << *(ptrCopy + i) << ": A " << endl; gpAvg += 4; } else if (*(ptrCopy + i) >= 90 && *(ptrCopy + i) < 94) { cout << *(ptrCopy + i) << ": A- " << endl; gpAvg += 3.7; } else if (*(ptrCopy + i) >= 87 && *(ptrCopy + i) < 90) { cout << *(ptrCopy + i) << ": B+ " << endl; gpAvg += 3.3; } else if (*(ptrCopy + i) >= 83 && *(ptrCopy + i) < 87) { cout << *(ptrCopy + i) << ": B " << endl; gpAvg += 3; } else if (*(ptrCopy + i) >= 80 && *(ptrCopy + i) < 83) { cout << *(ptrCopy + i) << ": B- " << endl; gpAvg += 2.7; } else if (*(ptrCopy + i) >= 77 && *(ptrCopy + i) < 80) { cout << *(ptrCopy + i) << ": C+ " << endl; gpAvg += 2.3; } else if (*(ptrCopy + i) >= 73 && *(ptrCopy + i) < 77) { cout << *(ptrCopy + i) << ": C " << endl; gpAvg += 2; } else if (*(ptrCopy + i) >= 70 && *(ptrCopy + i) < 73) { cout << *(ptrCopy + i) << ": C- " << endl; gpAvg += 1.7; } else if (*(ptrCopy + i) >= 67 && *(ptrCopy + i) < 70) { cout << *(ptrCopy + i) << ": D+ " << endl; gpAvg += 1.3; } else if (*(ptrCopy + i) >= 60 && *(ptrCopy + i) < 67) { cout << *(ptrCopy + i) << ": D " << endl; gpAvg += 1; } else if (*(ptrCopy + i) > 1 && *(ptrCopy + i) < 60) { cout << *(ptrCopy + i) << ": F " << endl; } } cout << "*******************" << endl; //Feature 1- Dropped scores for (int i = 0; i < sNum; i++) cout << *(ptrLow + i) << " [Dropped Score] " << endl; // Calculation of GPA and displaying results rNum -= sNum; cout << fixed << setprecision(2) << endl; gpAvg = (gpAvg / rNum); cout << " Grade Point Average (GPA): " << gpAvg << endl; cout << endl; //Feature 3- Overall grades, GPA and Comments for the grades if (gpAvg == 4) { cout << " Grade: A" << endl << endl; cout << " Excellent Job! " << endl; cout << " Keep up the good progress! " << endl; } else if (gpAvg < 4 && gpAvg > 3.67) { cout << " Grade: A-" << endl << endl; cout << " Good Score! " << endl; cout << " Keep Going! " << endl; } else if (gpAvg < 3.67 && gpAvg > 3.33) { cout << " Grade: B+" << endl << endl; cout << " Good Work! " << endl; cout << " Study a little more. " << endl; } else if (gpAvg < 3.33 && gpAvg > 3) { cout << " Grade: B" << endl << endl; cout << " Good " << endl; cout << " Need to study even more! " << endl; } else if (gpAvg < 3 && gpAvg > 2.67) { cout << " Grade: B- " << endl << endl; cout << " Well done " << endl; cout << " but need to work hard, " << endl; cout << " since you are close to a C! " << endl; } else if (gpAvg < 2.67 && gpAvg > 2.33) { cout << " Grade: C+ " << endl << endl; cout << " Looks like the grades are slipping " << endl; cout << " Need to spend more time studying! " << endl; } else if (gpAvg < 2.33 && gpAvg > 2) { cout << " Grade: C " << endl << endl; cout << " Getting low! " << endl; cout << " Need to work even harder! " << endl; } else if (gpAvg < 2 && gpAvg > 1.67) { cout << " Grade: C- " << endl << endl; cout << " Risky! Gotta study even more! " << endl; } else if (gpAvg < 1.67 && gpAvg > 1.33) { cout << " Grade: D+ " << endl << endl; cout << " Going low on your " << endl; cout << " chances of passing! " << endl; cout << " Work even more harder! " << endl; } else if (gpAvg < 1.33 && gpAvg > 1) { cout << " Grade: D " << endl; cout << " Chances of passing the class " << endl; cout << " are getting even lower! " << endl; cout << " Concentrate and study or seek help " << endl; cout << " from a tutor! " << endl; } else if (gpAvg < 1 && gpAvg > 0.67) { cout << " Grade: D- " << endl; cout << " Nearly no chances of passing! " << endl; } else if (gpAvg < 0.67) { cout << " Grade: F " << endl; cout << " Disappointing and dejecting! " << endl; cout << " Try Again or Opt for something else " << endl; } //Specification 1- Allows the user to calcualte the grades for as many students as they want cout << " Would you like to enter the grades for another student?"; cin >> rChoice; rChoice = toupper(rChoice); if (rChoice == 'Y') { cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); cout << " Enter name of the student (First and Last): "; getline(cin, stName); cin.clear(); cin.ignore(); mainEvent(); } //Specification 5- dumps data before program ends else if (rChoice == 'N') { cout << " Good Bye! " << endl; } } void gradeAdd() { cout << "\nEnter quiz # " << (count) << " score: "; cin >> *(ptr + count); //Feature 4- Input Validation to make sure that the test scores are neither negative nor more than 100 while (*(ptr + count) > 100 || *(ptr + count) < 0) { cout << " Sorry! Invalid Input! Please enter a value from 0-100: " << endl; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); cin >> *(ptr + count); } count++; } //Specification 4- Main Menu void mainMenu() { cout << "1. Add a grade" << endl; cout << "2. Display Results" << endl; cout << "3. Quit" << endl; } int getUserChoice() { int userInput; cin >> userInput; //Feature 5- Input validation to make sure user enters only options 1- 3 from the menu while (userInput != 1 && userInput != 2 && userInput != 3) { cout << " Invalid Choice! Please enter a choice from 1 to 3: " << endl; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); cin >> userInput; } return userInput; }