C++, I am tried to make this exercise: 2) Write a program and declare an array called “Exam” with 100 integers. Hence, ask a lecturer to enter the number of students in a class along with each student’s mark that should be stored in the array (use a variable n to know the number of students). The program should then calculate and display: a) the average (float) and the highest and lowest marks of the class, b) the number of grades A, B, C, D and F, according to the following table. There is something wrong with the code I just don't understand what it is? http://pastebin.com/14nZDb5A
hard to help if the pastebin is removed.
Sorry I re-added it !!
use Exam[100] not Exam(100) Exam(100) means you are inputting argument 100 to function Exam() while int Exam[100]; means you are declaring an array of type int with size 100
ooh I see
You may want to make sure that the user doesn't input a number bigger than the length of your student array. To gather the As, Bs, Cs, Ds and Fs, I would have an array to count them. It's also pretty simple to output. You may want to use a switch statement for collection. Don't forget that you can assign a value to a variable when you declare it. Many people recommend doing this so that they'll have known values instead or (somewhat) random garbage values.
And from a programming standpoint, globals are a bad idea. ``` #include <iostream> using namespace std; int Exam[100]; int n; float average; int highest; int lowest; int Students; int Grade; int i; int GradeSum=0; int Average; bool FirstTime; bool FirstTime2; int main() { ``` Those are globals. ``` #include <iostream> using namespace std; int main() { int Exam[100]; int n; float average; int highest; int lowest; int Students; int Grade; int i; int GradeSum=0; int Average; bool FirstTime; bool FirstTime2; ``` That changes them to local.
Join our real-time social learning platform and learn together with your friends!