Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (christos):

C++ , I need to solve this 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, The highest and lowest variable is always giving me 0. I don't know why ? Can you please tell me how to fix this problem? http://pastebin.com/LjGUyLXe

OpenStudy (inkyvoyd):

is the average working?

OpenStudy (christos):

the average is working

OpenStudy (inkyvoyd):

you should probably comment your code

OpenStudy (christos):

on what exactly ? that's the point

OpenStudy (christos):

by comment you mean //comment ??

OpenStudy (inkyvoyd):

yes, for every group of statements, especially vague variable names

OpenStudy (inkyvoyd):

also, the indentation of your code is incorrect. Check line 34. I'm having trouble just reading your code because of the indentation

OpenStudy (inkyvoyd):

I understand that your code makes sense to you probably, but if you're going to ask for help it won't really be effective unless you do minimal documentation of your code and utilize whitespace correctly.

OpenStudy (inkyvoyd):

anyways, it's more than likely that I won't provide any more help until you decide to clean up the formatting and update the pastebin. And if you do this - it's more than likely you'll find what went wrong yourself.

OpenStudy (e.mccormick):

Like I said before, because the teacher is having you find out about arrays, the best thing to do is to separate loops. Before the firs loop, find out how many students there are. Loop that many times. The first loop will go through and let the person enter grades. The second loop will go through and evaluate things, sum up the number of each, and find the highest/lowest.

OpenStudy (e.mccormick):

Lets try this... just gonna write code, so not 100% sure this will run... ``` int a[]={1,9,7,2,0}; int low = 200; int high = -200; for (int i = 0; i<5;i++); { if (a[i]<low) low = a; if (a[i]>high) high = a; } cout << "The high is: " << high << "\nThe low is: " << low << endl ; ```

OpenStudy (e.mccormick):

Oops... I meant low=a[i]...

OpenStudy (christos):

Thanks man! I solved it anyways but I really appreciate it !!

OpenStudy (e.mccormick):

So you done with this assignment finally?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!