Why doesn't the if else statement work? Please help...
YESH.CPP
#include<stdio.h>
#include<conio.h>
void main()
{
long int numbers;
int a,b,c,d,e,f,g;
printf("enter the 7 digits:\n\n\n\n\n");
scanf("%ld", &numbers);
a=numbers/1000000;
b=numbers%1000000/100000;
c=numbers%100000/10000;
d=numbers%10000/1000;
e=numbers%1000/100;
f=numbers%100/10;
g=numbers%10;
clrscr();
{
if(a==1|2|3|4|5|6|7|8|9|0)
printf("the value is %d \n",a);
if(b==1|2|3|4|5|6|7|8|9|0)
printf("the value is %d \n",b);
if(c==1|2|3|4|5|6|7|8|9|0)
printf("the value is %d \n",c);
if(d==1|2|3|4|5|6|7|8|9|0)
printf("the value is %d \n",d);
if(e==1|2|3|4|5|6|7|8|9|0)
printf("the value is %d \n",e);
if(f==1|2|3|4|5|6|7|8|9|0)
printf("the value is %d \n",f);
if(g==1|2|3|4|5|6|7|8|9|0)
printf("the value is %d \n",g);
}
if (a>b&c&d&e&f&g)
printf("the largest number is %d:",a);
else if(b>a&c&d&e&f&g)
printf("the largest number is %d:",b);
else if(c>a&b&d&e&f&g)
printf("the largest number is %d:",c);
else if(d>a&c&b&e&f&g)
printf("the largest number is %d:",d);
else if(e>a&c&d&b&f&g)
printf("the largest number is %d:",e);
else if(f>a&c&d&e&b&g)
printf("the largest number is %d:",f);
else if(g>a&c&d&e&f&b)
printf("the largest number is %d:",g);
getch();
}
Creating such if-else logics is tricky. Remember you're talking to a compiler through C++, not another person. The compiler will not be able to generate the correct true or false you want from your conditions.
I suggest you approach the problem a different way, perhaps through a variable which you then compare one at a time( it's not a lot of code if you do it the smart way )
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.