Jump to content

Any C programming super geeks out there?


eetaylog

Recommended Posts

if(a==1 && b==1 && c=1) { do something } else { do something else }

 

hang on a minute, ive just looked at your answer again and i dont think its exactly what im looking for, what i need is a statement that says

 

if(x,y and z are all the same value)

 

{function}

 

else

 

{function}

 

what yours says is:

 

if(x=1 and b=1 and c=1)

 

{function}

 

else

 

{function}

 

or am i missing something?

Edited by eetaylog
Link to comment
Share on other sites

if(a==1 && b==1 && c==1) { do something } else { do something else }

 

You missed a bit ;)

 

I missed a lot, but the essence is there. I'd expect people understand the use of semi-colons if they're writing C!

 

if(a==1 && b==1 && c=1) { do something } else { do something else }

 

hang on a minute, ive just looked at your answer again and i dont think its exactly what im looking for, what i need is a statement that says

 

if(x,y and z are all the same value)

 

{function}

 

else

 

{function}

 

what yours says is:

 

if(x=1 and b=1 and c=1)

 

{function}

 

else

 

{function}

 

or am i missing something?

 

 

I think you must be missing something.

Link to comment
Share on other sites

ok, so if i use the program below (some of the maths is missing but youll get the idea) with your if statement, then if x,y and z are equal (for any value, i.e x,y and z = 5 or x,y,z = 10) i will get OUTPUT1, otherwise ill get OUTPUT2. correct?

 

main()

 

{

 

float a1, float a2 float b1, floatb2, float c1 float c2, float x, float y, float z;

 

printf("please enter values a1,b1 and c1\n");

scanf(%f%f%f,a1,b1,c1);

 

printf("please enter values a2,b2 and c2\n");

scanf(%f%f%f,a2,b2,c2);

 

x = a2/a1;

 

y = b2/b1;

 

z = c2/c1;

 

if(a==1 && b==1 && c=1)

 

{

printf("OUTPUT1\n");

}

 

else

 

{

printf("OUTPUT2\n");

}

 

}

Edited by eetaylog
Link to comment
Share on other sites

fyi, ive done it this way now. seems to work:

 

x = a2/a1;

y = b2/b1;

z = c2/c1;

 

test = (x+y+z)/3;

 

if(test=x)

...

 

else

...

 

But what if

 

X=5

Y=6

Z=4

 

test = (5+6+4)/3;

If(5=5)

 

But X was not the same as Y or Z...

 

Maybe you want to compare X to Y if true then compare X to Z

Edited by bluliz
Link to comment
Share on other sites

But what if

 

X=5

Y=6

Z=4

 

test = (5+6+4)/3;

If(5=5)

 

But X was not the same as Y or Z...

 

Maybe you want to compare X to Y if true then compare X to Z

 

<3 :rolleyes:

 

i know what youre saying, i spotted this earlier as well. eg,

 

x=5

y=7

z=3

 

would slip through the net so to speak.

 

i think ive got around it now though by using

 

x = a2/a1;

y = b2/b1;

z = c2/c1;

 

test1 = x/y;

test2 = y/z;

 

if(test1&&test2=1)

...

 

else

...

 

i will have to wait til monday to test it on a DSP now though.

 

@stu.. im writing a program that solves simultaneous equations, ie, the solutions to

 

a1x + b1y = c1

a2x + b2y = c2

 

ive got most of the program wrapped up, just couldnt get the if-else loop bit right. ill stick my full program on here later on if youre interested.

Edited by eetaylog
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...