I believe she fixed the problem. No 100%, but I'm pretty sure she did.

I'd also nitpick your prompts that don't end in a newline because they might not show up on all systems before scanf() blocks for input. But those are minor issues for strict conformance.

do you mean that code

printf("\nPress Q then press Enter to quit\n");
      scanf("%c",&ch);

there problem happen when i run my code and press e (for Enter)in

      printf("\nPress E then press Enter to Enter Complex Number");
      printf("\nPress Q then press Enter to quit\n");
      scanf("%c",&ch);

will go to :

     if(ch=='E'||ch=='e') // if user enter E or e from keyboard
     {
         //clrscr();
         printf("\nPlease enter the two real and imaginary complex numbers (a+jb)    :\n");
         printf("\nreal number:");
         scanf("%d",&x.real);
         printf("\nImaginary number:");
         scanf("%d", &x.imag);
     }

after enter data(real and imag)then repeat that code two time

      printf("\nPress E then press Enter to Enter Complex Number");
      printf("\nPress Q then press Enter to quit\n");
      scanf("%c",&ch);

like this:

Press E then press Enter to Enter Complex Number
Press Q then press Enter to quit
Press E then press Enter to Enter Complex Number
Press Q then press Enter to quit

then wait me to enter E or Q
why this happened????????

do you mean that code

No, I mean this code:

printf("\nreal number:");
scanf("%d",&x.real);
printf("\nImaginary number:");
scanf("%d", &x.imag);

There's no guarantee that you'll see "real number:" before scanf() blocks for input, which means the user will have no clue what the program is waiting for. If you're not ending the prompt with a newline, I'd recommend calling fflush() to ensure that the prompt will be visible at the right time:

printf("\nreal number:");
fflush(stdout);
scanf("%d",&x.real);
printf("\nImaginary number:");
fflush(stdout);
scanf("%d", &x.imag);

why this happened????????

Probably because you're mixing single character input with formatted input. They don't mix well. To see exactly what characters are being processed, just output ch immediately after scanf() returns. I'm willing to bet you'll be surprised.

Yeah, i fixed it :) thanks guys for all your help, especially Jake :D <3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.