Web Analytics Made Easy -
StatCounter Rudimentary C++ Coding Assignment - CodingForum


No announcement yet.

Rudimentary C++ Coding Assignment

  • Filter
  • Time
  • Show
Clear All
new posts

  • Rudimentary C++ Coding Assignment

    Hey guys. I'm not sure if this is the right place to put this but I just needed some help completing the code I'm writing in C++ and was hoping someone here could write it for me or point me in the right direction because my professor has not been any help and hasn't responded to my emails. Anyway, as I said before I'm coding in C++ and my assignment is thus:

    Part 1:

    Write a program that uses a while loop to read in test scores until the user enters a negative number.
    Print the average score after dropping the highest and lowest scores.
    Print an error message if the user enters less than 3 scores.

    Part 2:

    Do the same calculation using a for loop, but in this case first ask the user how many scores they
    want to enter, then get the scores in a for loop.

    You can assume the test scores are from 0 to 100.


    After the loop completes, you need to have 4 pieces of information:

    1. How many scores: count
    2. The sum of all the scores: sum
    3. The highest score: hi
    4. The lowest score: lo

    The answer is then: (sum - hi - lo)/(count - 2)

    The hi and lo values can be computed in the loop with the following algorithm:

    for each score:
    if score < lo
    lo = score
    if score > hi
    hi = score

    Remember you need to initialize count, sum, hi, and lo before the loop begins.
    And this is as far as I've gotten:

    #include <iostream>
    using namespace std;
    int main() 
    	int count, sum, lo, hi, num;
    	int temp=count;
    	if(count<3) cout<<"error"<<endl;
    	while ((num > 0)&&(count--))
    	return 0;
    Someone else who was helping me a few days ago helped me understand how to get this far but our session was cut short. They suggested certain things you will see in the code that had not been taught to our class and certain syntax that was not easy to assume had to be part of the code. Can anyone shed some light on how to complete this code? Thanks for the help!

  • #2
    What happens when you run it?
    What is the problem with your code?
    What is it not doing?

    I will highlight this:
    Remember you need to initialize count, sum, hi, and lo before the loop begins.
    You have not done this, you have declared them but not initialized them; this could be very important as declaring allocates memory but does not necessarily set them to any particular value.