1. ## 1st Assignment

I have this program which I have to do. I am stuck because I haven't been programming in a while, therefore I forgot a couple of things. If anyone would be able to help me with anything and get me started with this program, I would be very grateful.

Here it is:
This Program should calculate weighted averages of grades. The program should also help answer this question: “how much to I have to get on the final in order to get an (x)?”

The program should open with heading on the screen which asks the user how many tests will be given during a semester. Then, the program should this number, n, and an empty integer array, percentages, to a void function. The void function should fill percentages by asking the user what percent of the grade is each test. The sum of all the percentages must be 100. If it is not there should be error message which should make the user reenter the information.

Once the percentages array is full, you should give the user one of two options. (Each of these options should be done by done by a separate function)

1) Allow the user to enter the n test grades and calculate the weighted averages of the grades.

2)Allow the user to enter in n-1 grades. First ask the user which test grade, k, the user is not entering (note 1<=k<=n.) Then enter in all but the k-th grade (hint: use continue in a for loop). Ask the user what he would like to get above as an average. Call this double variable above. Then calculate and print what the student needs to get in the k-th test to earn a grade higher then above. Now simply solve for x.)

Once this is done, allow the user to enter in the information for another student, or an option to stop.

Any help is greatly appreciated.

2. Post any of your attempts.

Since the percentages are integers, you could use an array with 100 elements to store the grades; that would be the most grades you could have (if 0% is invalid).

3. Well, I'm just blanking on this.

Ok. First will come the printf statement which the user will give the N number of grades. N will be the number given to an integer array (percentages [n]. How do I write this so far? What will be the code?

4. printf() the question (like "How many grades are there?") and scanf() the answer. You can declare the array to be 100 in size, but only use the number of elements that the user entered.

 You've covered functions, right? [/edit]

5. Good post Zeff, but I have no idea what you're stuck on!

You have forgotten some things - but I have no idea what it is that you've forgotten, so I have no clue how to help you. Ironically, you may have forgotten what it is that you've forgotten, and have no clue either on how to proceed! (okay, enough humor for now)

Post up what you've got as pseudocode to solve this and I'll be back in 1 hour to assist. I'm sure others will, as well - but we'd like to see your work, and much more specific questions on what's got you stumped.

Here's some info on using weighted averages:

Grades are often computed using a weighted average. Suppose that homework counts 10%, quizzes 20%, and tests 70%.

If Pat has a homework grade of 92, a quiz grade of 68, and a test grade of 81, then
Pat's overall grade = (0.10)(92) + (0.20)(68) + (0.70)(81) = 79.5

Remember to use two equal signs for an equality test, not just one like silly Mathematicians!

Back in 1 hour, show me what you've got, regards,

6. :mrgreen:
Only PHPBB boards have the mrgreen smiley.

Since the number of grades entered varies, to calculate the average you'd use something like this:
Code:
```int x, sum = 0;
double average;

for(x = 0; x < grades; x ++) {
}

7. Ok. so,

Int n=0;
int percentages[]; // it should be empty

scanf("%d",&n);

How do I then send the number N and the empty interger to a viod function?

8. Code:
`int percentages[]; // it should be empty`
No it shouldn't. That won't compile. As I said, put 100 in there because that's the most you'll need.
How do I then send the number N and the empty interger to a viod function?
Pass parameters. http://www.cprogramming.com/tutorial/c/lesson4.html

9. Thanks !

I'll do the lesson.

2 years ago when I was programming, i knew all this stuff. I just forgot simply everything.

10. Ok, so something like this?

Int n=0;
int percentages[100];
void fill (int n, int []);

scanf("%d",&n);

and then

fill(n, percentages);

??

11. Yes, the actual declaration of the function would look like this (sort of like main()):
Code:
```void fill(int n, int array[]) {

}```
where array is whatever you want to call the grades array.

BTW, printf() is spelled with a lowercase 'p'. C is case-sensitive. Int is int, etc.

12. Ohh ok.

void fill(int n, int percentages[]);

13. so passing to the function is correct

ex

fill(n,percentages) ?

14. Code:
`void fill(int n, int percentages[]);`
Exactly. That's the prototype. For the declaration, leave out the ; and add a block {} (like main()).

so passing to the function is correct

ex

fill(n,percentages) ?
Yes.

15. Ok thanks.

So now i try to write the whle function:

This is what it should do: The void function should fill percentages by asking the user what percent of the grade is each test. The sum of all the percentages must be 100. If it is not there should be error message which should make the user reenter the information.

So,

void fill(int n, int percentages[])
{
int ??? what do I need to declare here?

printf("What is the first test grade: ")
scanf(" .... how do I fill the array with the appropriate test grade and then ask what percentage it is?