-8

code is following:

#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <stdlib.h>
void main(void)
{
int a, b;
printf("enter a");
scanf("%d",&a);
printf("enter b");
scanf("%d",&b);
if(a==1 && b<=8)
{
    printf("you");
}
else if(a==2 && b<=10)
{
    printf("you");
}
else
    printf("me");
}
getch();
}

i edit again my question i found solution check please if there any syntax error.

shoaib sabir
  • 605
  • 2
  • 9
  • 23
  • 2
    Are you sure the code you have posted compiles? there is a mess with the else. – Yuval Ben-Arie Jul 23 '17 at 12:39
  • 2
    Use `if else` instead of `if` for the second `if`.Also i am wondering how you are going to identify which `if` printed `you`? – Gaurav Sehgal Jul 23 '17 at 12:40
  • 3
    Please read a good beginners book. C and C++ are two separate languages, `iostream.h` is not part of the C standard (and using `conio.h` is highly discouraged) and `void main(void)` isn't standard in either language – UnholySheep Jul 23 '17 at 12:42
  • The C++ books are [listed here](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – Ron Jul 23 '17 at 12:44
  • 3
    Don't use Turbo C++ or another ancient compiler that still supports `#include `. –  Jul 23 '17 at 12:51

1 Answers1

0

You are not following general if-else block property

if(a==1 && b<=8)  // This is independent if 1
{
    printf("you");
}

Then this is another if-else either of if or else in this block will get executed independently of what has previously happened

if(a==2 && 5<b && b<=10)   //  This is independent if-else block 2
{
    printf("you");
}
else
    printf("me");

For achieving what you want it should be if, else if and else block

if(a==1 && b<=8)
{
    printf("you");
}
else if(a==2 && 5<b && b<=10)
{
    printf("you");
}
else
    printf("me");
Isha Agarwal
  • 420
  • 4
  • 12