I need to find the find the highest final mark from 5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//trying to find the highest final mark
#include <iostream>
#include <string>
using namespace std;

void findhighest(int studentp[],int finalmarkp[], float highestp, int countp)
{
  highestp = 0;
  
  for (int i = 0; i < number; i++)
     {
       if (finalmarkp[i] > highestp)
          highestp = finalmarkp[i];
          if (finalmark[i] >= 75)
          countp++; 
        cout<<"Student number: "<<studentp[i]<<"Percentage: "<<finalmarkp[i]<<endl;
     }
}  

int main() //this part runs perfectly but with Function it does not 
{
    const int number = 5;
    int student[number] = {102452,2541236,698745,147852,258963};
    int finalmark[number];
    float highest;
    int count = 0;
    
    for (int count = 0; count < number; count++) // getting input rainfall from user for each month
	{
		cout << "Enter highest mark for " << student[count] << ":";
		cin >> finalmark[count];
	}
      findhighest(student, finalmark, highest, count);
   return 0;
}
Last edited on
When asking a question, please do the following:

1) actually ask a question
2) use code tags (put your code inside of [code] and [/code])
3) tell us what the problem is. "It doesn't work" is too vague and does not tell us anything.
4) If you are getting a compiler error, tell us what the error is (preferably, paste the full error message) and tell us what line it's on
5) Otherwise, if the program compiles and does not do what you expect, tell us what you expect it to do, and tell us what it is actually doing.
I took your advise and i never knew about code tags, basically the code needs to find the highest mark between student's mark entered.

When the function head is not included in the code it runs alright but the minute i put in the function head it does nothing.
You are trying to use 'number' and 'finalmark' inside of your findhighest function, but those variables only exist in main.

You are passing 'finalmark' to the function, which is good, but then it is named 'finalmarkp' inside findhighest. So you should be using that name. You will also need to pass 'number' to the function so you can use it there as well.

Also, I don't see why you need to pass 'highestp' and 'countp' to that function. They don't seem to do anything.
I corrected the mistakes in my code but it still not doing nothing...passed number to a function...
Last edited on
Topic archived. No new replies allowed.