Write a program that receives the number of students the users wants to enter as an input. Next, the program should ask the users to enter the marks that each of the students received for the number of students specified earlier by the user.
Lastly, the program should display the student’s mark for the student that received the highest marks; the lowest mark; and the average mark.
Please help
[code]
const unsigned int sizeArry{ 5 };
float Mark[sizeArry]{}
unsigned int count{ 0 };
it is unlikely that any student actually got the average score.
that aside, you can get the high, low, and total as they are entered, you just need variables to store them. you will have to loop after to find anyone with the average, or median, or something close to it, or nothing at all, for that one.
Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.
You can use the preview button at the bottom to see how it looks.
*** I found the second link to be the most help. ***
Looking over your instructions they feel rather lacking in content. It is best to pist the complete instructions that you were given. If this is what your were given than the program is less complex.
Although knowing the number of students you will have to work with I would just use a for loop.
Next you could call "count" "numOfStudents" or "numOfStuds" for better clarity of what the variable is for.
Although a "float" will work the preferred floating point variable type is a "double".
Since you should write your program in small pieces, compile and test often, this is an idea for you to start with.
// <--- Most common includes.
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
//#include <vector>
//#include <cctype>
int main()
{
constexprunsignedint SIZEARRAY{ 5 }; // <--- Or I like using "MAXSIZE".
constexprint WIDTH{ 47 }; // <--- Width of line under heading.
const std::string PROMPT{ "\n How many students will you be entering for?: " };
unsigned numOfStuds{};
double Mark[SIZEARRAY]{};
//unsigned int count{ 0 };
std::cout <<
'\n'
<< std::string((WIDTH - 17) / 2, ' ') // <--- Creates spaces to center heading.
// The 17 is the width of the next line minus the (\n and \0) at the end.
<< "Heading if needed.\n " // <--- Change as needed.
<< std::string(WIDTH, '-') // <--- Creates a line of (-) under heading.
<< '\n';
while (std::cout << PROMPT && !(std::cin >> numOfStuds))
{
if (!std::cin)
{
std::cerr << "\n Invalid Input! Must be a number.";
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
}
}
// <--- Keeps console window open when running in debug mode on Visual Studio. Or a good way to pause the program.
// The next line may not be needed. If you have to press enter to see the prompt it is not needed.
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // <--- Requires header file <limits>.
std::cout << "\n\n Press Enter to continue: ";
std::cin.get();
return 0; // <--- Not required, but makes a good break point for testing. Comment or remove when finished.
}