Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Problem Details: Write a C++ console program that prompts a user to enter a 2 digit Student ID (an integer ie 01) and a grade (a decimal number ie 89.72). After each entry, display the student’s letter grade and prompt user to either continue with input or stop input. Loop until user has no more entries.
After user termination, the program should:
1)Display the number of students entered and the average grade.
2)Display the Student ID of the lowest grade AND the corresponding grade.
3)Display the Student ID of the highest grade AND the corresponding grade.I've managed to make everything work except #2 and #3. How would I code for the Student ID of lowest and highest grades and display each individually?
I'm using MS Visual C++, Intro Edition.
-----------
This is the code I have thus far:#include
#include
#includeusing namespace std;
int main()
{
// declare variables
int nrstu = 0; // nr of students
char repeat = ' '; // setup variable for repeat sequence
char lgrade = ' '; // letter grade
float stuAverage = 0.0; // grade average
int total = 0; // grade sum
// declare arrayint x = 0;
// int y = 0;
int stuid[25] = {int (0)}; //stuid array
float grade[25] = {float (0.0)}; //grade array// int x = 0; // increments array placement - move next grade to x
// float temp = 0.0; // used for swapping
// int maxSub = 10; // maximum subscript
// int lastSwap = 0; // position of last swap (important for extraction)
// char swap = 'Y'; // was swap made?
// int gradeCounter = 1; // counter//Project comment header
cout > repeat;
while (toupper(repeat) == 'Y') // convert user input to upper case
{
//user input
cout > stuid[x];
cout > grade[x];
cout = 90.00)
lgrade = 'A';
else if
(grade[x] >= 80.00)
lgrade = 'B';
else if
(grade[x] >= 70.00)
lgrade = 'C';
else if
(grade[x] >= 60.00)
lgrade = 'D';
else lgrade = 'F';//end ifs
cout > repeat; // loop
total = total + grade[x]; // total grades entered
stuAverage = total / nrstu; // calc student average
} //end whilecout fixed;
cout.precision(2); //fix decimal notation at 2 placessystem("cls"); // clear screen
cout "The number of students entered was: " nrstu endl;
cout "and the student average was: " stuAverage endl;
cout endl;
// cout "The lowest grade was: " lowGrade endl; // sorted from array
// cout "and came from student ID: " lowStu endl;
// cout endl;
// cout "The highest grade was: " highGrade endl;
// cout "and came from studetn ID: " highStu endl;
return 0;
} //end of main functionAny suggestions?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |