Monday, 15 June 2015

struct - Whats wrong with getchar in C, please? -


I wrote this code to some algebra with hypothetical numbers using structs, but when I run it , Then give me this Enter the image details here

What I'm doing wrong , I tried all different ways to get the four, I am puzzled!

  contains # lt; Stdio.h & gt; #to & lt include, stdlib.h & gt; #include & lt; String.h & gt; Strip complex (float rays, imz;}; int main () {four operand; structure complex z1, z2; printf ("real part of the first fictional number Z1: \ n"); Scanf ("% f", & amp; Printf ("zreal =% f", z1.Rez); Printf ("fictional part of z1: first fictional number: \ n"); Scanf ("% f", & amp; z1.imz ); Printf ("Give the real part of the second fantasy number Z2: \ n"); Scanf ("% F", and 2. Rage); Printf ("Fictional part of second fantasy number z2: \ n"); Scanf ("% F", and & amp; z2.imz); {printf ("Enter for ADD" \ nGLITIPLICATION For GO \ nGive - SUBTRACTION for \ nGIVISION / \ n "); Sync = getchar (); If (operand! = '+' || operand! = '-' || operand! = '* * (Operend! = '/') Printf ("wrong operation., Try again. \ N");} while (operand! = '+' || operand! = '-' || operand! = '*' } Operand! = '/'); If (operand == '+') {printf ("\ n" you have chosen to add numbers. \ N The result of ADD is a random number \ imz = (% f + % F) + (% f +% f) + ", z1.Rez, z2.Rez, z1.imz, z2.imz); } If (operand == '-') {} if (operand == '*') {} if (operand == '/') {} system ("pause"); Return 0; }  

Any suggestions please? Iam stuck!

if (operand! = '+' || operand! = '-' || Operant! = '*' || Operation! = '/')

This statement is always true, because in most of the four situations, most of us can be wrong.

You should have written this:

if (operand! = '+' & Amp; amp; operand! = '-' and & amp; operand! = '*' And OPED! = '/')

While the same mistake for the loop: Always true, infinite loop


In addition, you feel that your getchar is wrong, but no arguments have been found to display your printf.

  symmetry = getchar (); Printf ("symmetry =% c");  

should have been:

  operand = getchar (); Printf ("operand =% c", operand);  

No comments:

Post a Comment