function Pass or fail

How can i go about writing a function for student doing 6 subjects the learner has to pass 4 subjects including english to pass that grade and the subject passmark is 50%... i am not sure how to go about it please assist

There are (at least) two parts in programming.
One is to be able to think, what to do.
The other is how to write it in language.


What is the input data? Is it a "table" of six (subject,score) pairs, where score is in range [0..100]?

It should be trivial to compute a bool (true/false) from a score.

Now you would have a (subject,score,pass) table. The actual data structure does not have to be table; an array of struct could be intuitive though.

If you have 6 pass values, you can count how many are true. In addition you can record the pass value of subject: english.

Now we are down to two values: count and english-pass.
IF english failed, THEN student failed
ELSE IF count is at least 4, THEN student passed
ELSE student failed

(That condition can be simplified.)
goodmorning i have not done tables or data structures but this is what i came up with


//using input marks show pass is four subjects passed including eng
#include <iostream>
using namespace std
int main()
int emark1, mmark2 ,smark3,fmark4,nmark5,clmark6,pass;

do{ cout<<"may you pliz enter your marks:"
cin>emark1>>mmark2>>smark3>>fmark4>>nmarks>>clmark6;

if(mmark2>=50&&smark3>=50&&fmark4>=50&&nmarks>=50&&clmark6>=50)
{pass=1,pass>=4,pass++}
cout<<"outcome:pass"
else
cout<<"outcome:fail"
} while (emark>=50)


Were have i gone wrong pliz assist
First, please use code tags when posting code. See http://www.cplusplus.com/articles/jEywvCM9/

Does your program compile? If not, what errors does your compiler list? That is useful information.


Arrays and loops work together:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// an array of 6 integers for the scores
std::array<int,6> marks;

// we fill the array somehow with scores

// assumption: english is the first subject
if ( 50 <= marks[0] ) // english passes
{
  int count = 0;
  for ( auto subj : marks ) {
    if ( 50 <= subj ) ++count;
  }

  if ( /*enough passes*/ ) {
    // show success
  }
  else {
    // show fail
  }
}
else // english fail -> all fail
{
  // show fail
}
Topic archived. No new replies allowed.