Greater and Less Than~

Hi, I tried to run the following code, but the output give 2 result when i insert a number (eg:56), may I know how to give only one output for each mark? eg: 56 only shows Pass instead of both Pass and Fail

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <conio>

int main ()
{
	double mark;

   cout<<"Enter your Test 1 mark>>";
   cin>>mark;

   if (mark>=80)
     	cout<<"TEST 1 -> Good"<<endl;

	else if  (mark<80 & mark>=50)
   	cout<<"TEST 1 -> Pass"<<endl;

   else  (mark<50);
   	cout<<"TEST 1 -> Fail"<<endl;
      cout<<"Try your best in your TEST 2"<<endl;

   getch();
   return 0;
}
else (mark<50);
should be
else if (mark<50)

Also, you're not using any namespaces. Get a more recent compiler that conforms to the C++ standard.
else if (mark<80 & mark>=50)

to:
else if (mark<80 && mark>=50)
Hi, Moschops, I'm using Borland C++ to run this program, that's why I don't use namespaces, but when I use Ms Visual Studio C++, I got use using namespace std; is that wat u mean? TQ...

And somemore, after I tried both of ur method above, I still got 2 answer, both Pass and Fail when tested with "56".
I think you must have not done what I told you to. I added an if and I removed a ;

Did you add the if ?

Did you remove the ; ?
Hi, Moschops, I did add if but does not notice there is ;, now problem solve, thanks! anyway, is there any wrong by adding ;? when should i add and when should not?
1
2
  if(foo < 3);
    bar = 3; // this will always run because the `;` at the end of the if statement ends the condition. 

Last edited on
else if (mark<50) there is no another possibillity for 'mark'
So you can use just
1
2
else
  //statement 
Topic archived. No new replies allowed.