Christos
  • Christos
C++, I need to do this problem 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. Can you please help me fix my code? http://pastebin.com/2LyVsufa
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
schrodinger
  • schrodinger
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
what errors do you get when you compile it
Christos
  • Christos
I cant make it so that it can print in array......
e.mccormick
  • e.mccormick
To print an antire array you need to loop through it.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

Christos
  • Christos
Is this closer to correct ? http://pastebin.com/dNvXxFid
e.mccormick
  • e.mccormick
Also, you have a bug. You print both A and F for As.
e.mccormick
  • e.mccormick
What are you trying to print out when you print: cout << Exam[Students]; ??
e.mccormick
  • e.mccormick
Also: ``` cout << "Average : " << Average; cout << "Highest : " << highest; cout << "Lowest : " << lowest; ``` prints out everything on one line! No spaces between, just BANG! there. I think you want: ``` cout << "Average : " << Average << endl; cout << "Highest : " << highest << endl; cout << "Lowest : " << lowest << endl; ``` or: ``` cout << "Average : " << Average << " "; cout << "Highest : " << highest << " "; cout << "Lowest : " << lowest << endl; ```
e.mccormick
  • e.mccormick
If grades can only be between 0 and 100, you can pre-set the highest to -1 and the lowest to 101. Then just use an if statement to change them as needed. No need to deal with first time at all.
e.mccormick
  • e.mccormick
Hmmm... and I do not see how this does the "b) the number of grades A, B, C, D and F, according to the following table." part, and you seem to be printing the letters for reasons other than answering the question... but that is not bad. Printing is a good way to test things.
e.mccormick
  • e.mccormick
I revised it, and mine prints out this: ``` Students : 10 Enter Grades : 70 C Enter Grades : 82 B Enter Grades : 89 B Enter Grades : 61 D Enter Grades : 65 D Enter Grades : 77 C Enter Grades : 63 D Enter Grades : 71 C Enter Grades : 78 C Enter Grades : 83 B Average : 73 Highest : 89 Lowest : 61 There were: 0 As, 3 Bs, 4 Cs, 3Ds, and 0Fs. ``` NOTE: Even though there are no As or Fs, I still get higest and lowest. But there is one more bug to find. The Average is incorrect. It is supposed to be a float, but did not produce one.
Christos
  • Christos
but yet again, ain't you supposed to print those things within an "array" ?
e.mccormick
  • e.mccormick
Print what things?
e.mccormick
  • e.mccormick
Use casting: ``` int var = 1 float f_var = (float)var ``` It fixes your output: Students : 5 Enter Grades : 54 F Enter Grades : 66 D Enter Grades : 77 C Enter Grades : 88 B Enter Grades : 99 A Average : 76.8 Highest : 99 Lowest : 54 There were: 1 As, 1 Bs, 1 Cs, 1Ds, and 1Fs.
e.mccormick
  • e.mccormick
OK: From what it says in the question, the output should be something more like this: Students : 7 Enter Grade #1: 79 Enter Grade #2: 62 Enter Grade #3: 93 Enter Grade #4: 44 Enter Grade #5: 88 Enter Grade #6: 57 Enter Grade #7: 78 Average : 71.5714 Highest : 93 Lowest : 44 There were: 1 As, 1 Bs, 2 Cs, 1Ds, and 2Fs.
Christos
  • Christos
So that's an array ? It fixes your output: Students : 5 Enter Grades : 54 F Enter Grades : 66 D Enter Grades : 77 C Enter Grades : 88 B Enter Grades : 99 A Average : 76.8 Highest : 99 Lowest : 54 There were: 1 As, 1 Bs, 1 Cs, 1Ds, and 1Fs.
e.mccormick
  • e.mccormick
I am not even sure why they are using an array in this one.
Christos
  • Christos
Yea me neither, it's my second problem with arrays so I am not even sure what an array is supposed to look like on an actual program
e.mccormick
  • e.mccormick
Ah, this is probably just to get you used to arrays. OK. So you probably need to do two loops. The first loop to take in the array. The second loop to evaluate the array.
Christos
  • Christos
hm
Christos
  • Christos
Would it be easy for you to provide me with a tiny bit example ?
e.mccormick
  • e.mccormick
You have most of it. Just don't do it all in one loop. Put things into the array in one loop, thenm the ifs in the second loop.
Christos
  • Christos
hm lets see
e.mccormick
  • e.mccormick
``` for (int i=0; i < Students;i++) { cout << "Enter Grade #" << i+1 << ": "; ``` That part would be the same... well, that was my vesrion of it. Then, your cin goes into the array at location i.
e.mccormick
  • e.mccormick
In sudocode, mine is: ``` #include using namespace std; int main() { declare a bunch of variables ask how many students for loop input grades into array for loop evaluate each student in array increment letter grade variables add up total of grades print results return 0; } ``` And I get: Number of students? 7 Enter grade for student #1: 67 Enter grade for student #2: 99 Enter grade for student #3: 76 Enter grade for student #4: 88 Enter grade for student #5: 32 Enter grade for student #6: 79 Enter grade for student #7: 81 7 students input. Now evaluating. Math completed! Average: 74.5714 Highest: 99 Lowest: 32 There were: 1 As, 2 Bs, 2 Cs, 1Ds, and 1Fs.
e.mccormick
  • e.mccormick
Any progress?
Christos
  • Christos
How did you fix highest and lowest variable @e.mccormick
Christos
  • Christos
? *
e.mccormick
  • e.mccormick
When I initialize high and low I put the high to a negative number and the low to a number over 100. Then every step I just compare those to every number. So the first number is higher than the high and lower than the low and changes both values. The second number might be higher or lower than this, so it may change one of them, so on and so forth.

Looking for something else?

Not the answer you are looking for? Search for more explanations.