Needs assistants

I am writing 2 functions for a group project program. They are very simple but I was sick during class when we talked about arrays so i'm looking for someone who wouldnt mind taking a little time to help me figure them out. All help would be greatly appreciated. I will be on my computer all day/night so my replies will be very quick..
closed account (S6k9GNh0)
Please be more specific. We can help you with arrays but, well, they're very simple.... What would you need help with?
Try this tutorial on arrays: http://www.cplusplus.com/doc/tutorial/arrays/

Example of array:
1
2
3
4
5
6
7
8
//You need 5 variables of the same type:
int var1=1, var2=2, var3=3, var4=4, var5=5;


//You want to type less and have things much easier
int array[5] = {1,2,3,4,5};

//notice that the first element of the array would be array[0] 
Last edited on
The first function is to take 2 arrays that's size is 6 and average them into a 3rd array.

one array is called midterm [76,92,65,71,90,88]
2nd array is called final [81,87,69,71,95,74]
and the 3rd would be mean [78.5,89.5,67.0,71.0,92.5,81.0]
Last edited on
closed account (S6k9GNh0)
Well, I won't give the answer away because this sounds like a classic case of making an excuse to get the answer to your homework. Simply put, you need to iterate through array 1 and 2 using a loop and the same variable. arrayone[i] and arraytwo[i] are accessed at element i. In that, you can average those to members by adding them and dividing them by two.
i dont want the answer..Just wanted a little help getting started..Having someone do it for me defeats the purpose of me wanting to learn how to do it..
Good man, trying to learn rather than get answers.

Bazzy's post shows it quite well.

Just to add a comment to explain:

1
2
3
int var1=1, var2=2, var3=3, var4=4, var5=5;

int array[5] = {1,2,3,4,5}; // Create an array to store the same values as in var1 through var5 


They're also useful if you want to do a loop:

1
2
3
4
for (int i=6; i>0; i--) {
  if i%2==0 // if i/2 leaves no remainder
  array[i] = i; // Store i in it's own place in the array
}
Last edited on
Once again I dont want anyone doing anything for me. I just need some help because i missed the lesson so Does this look correct?

void studentAvg(int midterm[], int final[], int size, double mean[]);
{
for( int i=0; i<size; i++)
{
mean[i]= (midterm[i]+final[i])/2;
}
}


Also does this function look alright?


void assignGrade(double mean[], int size, char grade[]);
{
for( int i=0; i<size; i++)
{
if(mean[i]>=90)
grade[i]='A';
else if(mean[i]>=80)
grade[i]='B';
else if(mean[i]>=70)
grade[i]='C'
else if(mean[i]>=60)
grade[i]='D'
else if(mean[i]<60)
grade[i]='F'
}
}
Last edited on
Everything looks okay.

Getting a little wacky, you could (but probably shouldn't) replace your "if/else if" ladder with this:

1
2
assert(mean[i] >= 0 && mean[i] <= 100);
grade[i] = "FFFFFFDCBAA"[mean[i] / 10];

But is the "if/else if" stuff right? Because thats what we have learned so far..Havent learned "assert" or the "ffffffdcbaa" even though i see how it works better..
Topic archived. No new replies allowed.