See, my program is suppose to run like this...1st the question "ENTER NUMBER OF STUDENTS(MAXIMUM OF 15)" would appear...and depending on the user's input..this statement is going to appear "ENTER RESULT:"..(If the user input 2 students..then the "Enter result statement would only appear twice)..After that it computes all the grades of all the students and shows the result of the class average...then it shows how many passed and what percent passed...and how many failed and what percent of the class failed...So far I got this
This was the code fr0om the PREVIOUS activity where we only needed to put '1' or '2' to say that a student passed or failed..therefor there was no need to put the average grade(since its only 1 or 2)...the later activity was more difficult...please help...
First of all, the type of the variables needs to be corrected.
float stud; represents number of students, which is a whoe number( can we have 1.5 students :-) so it should be
int stud;
All the increment variables used in the for loop should also be int
Sometimes I wonder what the problem with students is?
Do you not know how to calculate an (presumeably arithmetic) average?
I do not quite understand the problem?
Let the user enter a grade. Sum that grade up. Find out if it is a pass or a fail, sum that up.
Then calculate the average, and the two percentages.
And it is better to change char er; into a float or an integer (depending whether your grades can be only integers or if they might as well have values like 2.7).That would make the if thens easier to program.
Your for statements should not use floats/doubles.
Use: for (int i = 0; i < ?; ++i) { /* Put your code here */ } The For-Loop for the most part should begin at 0, not 1. This is because all of your arrays will start at 0, not 1.
While starting at 1 and using <= will work for you. I'd advise against this habit because you will end up coding bugs into array code without knowing :)
sum = i++;. This code is really pointless. And the way it works is terrible to understand.
1 2 3 4 5 6 7
int sum = 0;
int sum1 = 0;
if (er == '1')
sum++;
else
sum1++;
There is no need for y or i to be defined (i should be used in your loops, not x).