Complex Numbers

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 12
Reputation: jcr1 is an unknown quantity at this point 
Solved Threads: 0
jcr1 jcr1 is offline Offline
Newbie Poster

Complex Numbers

 
0
  #1
Nov 8th, 2004
Any tips on starting a complex number calculator program?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 12
Reputation: jcr1 is an unknown quantity at this point 
Solved Threads: 0
jcr1 jcr1 is offline Offline
Newbie Poster

Re: Complex Numbers

 
-1
  #2
Nov 8th, 2004
This is what i have at the moment.#include <stdio.h>
void main()
{

int a_real,a_imaginary;
int b_real,b_imaginary;

printf ("a real = ");
scanf ("%d",&a_real);

printf ("a imaginary = ");
scanf ("%d",&a_imaginary);

printf ("b real = ");
scanf ("%d",&b_real);
printf ("b imaginary = ");
scanf ("%d",&b_imaginary);


}
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: Complex Numbers

 
0
  #3
Nov 8th, 2004
Hello,

It might help to know what type of calculator program you are looking for. You might want to structure it so that the user has to input a function...

  1. Welcome to the Calculator Program.
  2. Would you like to Add, Subtract, Divide, or Multiply (A,S,D,M)?
  3.  
  4. You chose to _
  5.  
  6. Please enter in your 1st Number: __
  7. Please enter in your 2nd Number: __
  8.  
  9. Your answer is: ____
  10.  
  11. Would you like to calculate another?

Now, keep these things in mind:

* DO NOT ALLOW YOUR COMPUTER TO DIVIDE BY ZERO. That could crash out the computer, and give the user a nasty message. Put a check in there to ensure that b <> 0

* Be careful with the imaginary numbers. Review how they work.

* If you have to add trig functions, then make sure they follow the rules too.

* How are you going to handle exponents?

Some enhancement ideas:

* Implement a memory function that can store a value to be compared with later.

* Implement a small array, say 25 numbers, that you can average together or sort out (kinda like an adding machine thing).

Christian
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 12
Reputation: jcr1 is an unknown quantity at this point 
Solved Threads: 0
jcr1 jcr1 is offline Offline
Newbie Poster

Re: Complex Numbers

 
0
  #4
Nov 9th, 2004
cheers, i do need the user to put in a function either +,-,/,*.To calculate the complex number e.g. (1+j2) + (-6-j6) and it has to output the results in cartesian co-ordinates.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 12
Reputation: jcr1 is an unknown quantity at this point 
Solved Threads: 0
jcr1 jcr1 is offline Offline
Newbie Poster

Re: Complex Numbers

 
0
  #5
Nov 9th, 2004
What is wrong with the if statement, according to my notes its right but it keeps telling me ! expression syntax.
#include <stdio.h>
void main()
{

int a_real,a_imaginary;
int b_real,b_imaginary;
int complex_number;

int enter_operator;
printf ("a real = ");
scanf ("%d",&a_real);

printf ("a imaginary = ");
scanf ("%d",&a_imaginary);

printf ("b real = ");
scanf ("%d",&b_real);
printf ("b imaginary = ");
scanf ("%d",&b_imaginary);
printf ("Enter operator = ");
scanf ("%d",&enter_operator);
if (enter_operator = +);
complex_number = (a_real+b_real)+j(a_imaginary+b_imaginary);
if (enter_operator = -)
complex_number = (a_real-b_real)+j(a_imaginary-b_imaginary);


}
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,865
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Complex Numbers

 
0
  #6
Nov 9th, 2004
>according to my notes its right
And your notes have to be correct? Nope, sorry.

>void main()
int main ( void )

>int enter_operator;
char enter_operator;

>scanf ("%d",&enter_operator);
scanf ("%c",&enter_operator);

>if (enter_operator = +);
if (enter_operator == '+')

>if (enter_operator = -)
else if (enter_operator == '-')

>}
return 0;
}

Clear?
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 12
Reputation: jcr1 is an unknown quantity at this point 
Solved Threads: 0
jcr1 jcr1 is offline Offline
Newbie Poster

Re: Complex Numbers

 
0
  #7
Nov 9th, 2004
That,s no good either,it's given me more errors.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,865
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 755
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Senior Bitch

Re: Complex Numbers

 
0
  #8
Nov 9th, 2004
>That,s no good either
Then you're doing it wrong.

>it's given me more errors
Please start giving us workable information instead of complaining about your mythical non-working code. Your idiocy isn't entertaining anymore. More specifically, post the errors you get, and the code that causes them.
New members chased away this month: 5
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 12
Reputation: jcr1 is an unknown quantity at this point 
Solved Threads: 0
jcr1 jcr1 is offline Offline
Newbie Poster

Re: Complex Numbers

 
-1
  #9
Nov 12th, 2004
int main (void)
{

int a_real,a_imaginary,j;
int b_real,b_imaginary;
int complex_number;

char enter_operator;
printf ("a real = ");
scanf ("%d",&a_real);

printf ("a imaginary = ");
scanf ("%d",&a_imaginary);

printf ("b real = ");
scanf ("%d",&b_real);
printf ("b imaginary = ");
scanf ("%d",&b_imaginary);
printf ("Enter operator = ");
scanf ("%c",&enter_operator);
if (enter_operator == '+') complex_number = (a_real+b_real)+j(a_imaginary+b_imaginary);

printf ("\ncomplex number is %d\n",complex_number);
else if (enter_operator == '-');
complex_number = (a_real-b_real)+j(a_imaginary-b_imaginary);
printf ("\ncomplex number is %d\n",complex_number);

else if (enter_operator == '/');
complex_number = ((a_real*b_real+a_imaginary*b_imaginary)/(b_real*b_real)+(b_imaginary*b_imaginary))+j((a_imaginary*b_real-a_real*b_imaginary)/(b_real*b_real+b_imaginary*b_imaginary));
printf ("\ncomplex number is %d\n",complex_number);

else if (enter_operator == '*');
complex_number = ((a_real*b_real)-(a_imaginary*b_imaginary))+j((a_real*b_imaginary)+(a_real*b_real));
printf ("\ncomplex number is %d\n",complex_number);
return 0;
}
errors
call of notification
misplaced else
code has no effect
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 220
Reputation: frrossk is an unknown quantity at this point 
Solved Threads: 9
frrossk's Avatar
frrossk frrossk is offline Offline
Posting Whiz in Training

Re: Complex Numbers

 
0
  #10
Nov 12th, 2004
I assume #include <stdio.h>

int main (void)
{

     int a_real,a_imaginary,j;
     int b_real,b_imaginary;
     int complex_number;

     char enter_operator;
     printf ("a real = ");
     scanf ("%d",&a_real);

     printf ("a imaginary = ");
     scanf ("%d",&a_imaginary);

     printf ("b real = ");
     scanf ("%d",&b_real);
     printf ("b imaginary = ");
     scanf ("%d",&b_imaginary);
     printf ("Enter operator = ");
     scanf ("%c",&enter_operator);
     if (enter_operator == '+') 
{
complex_number = (a_real+b_real)+j(a_imaginary+b_imaginary);

        printf ("\ncomplex number is %d\n",complex_number);
}
     else if (enter_operator == '-')
{
        complex_number = (a_real-b_real)+j(a_imaginary-b_imaginary);
        printf ("\ncomplex number is %d\n",complex_number);
}
     else if (enter_operator == '/')
{
        complex_number = ((a_real*b_real+a_imaginary*b_imaginary)/(b_real*b_real)+(b_imaginary*b_imaginary))+j((a_imaginary*b_real-a_real*b_imaginary)/(b_real*b_real+b_imaginary*b_imaginary));
        printf ("\ncomplex number is %d\n",complex_number);
}
     else if (enter_operator == '*')
{
        complex_number = ((a_real*b_real)-(a_imaginary*b_imaginary))+j((a_real*b_imaginary)+(a_real*b_real));
        printf ("\ncomplex number is %d\n",complex_number);
}
     return 0;
}

First, if in an if statement you have more than one single instruction, you have to put these instructions between { and }
Second, else if (expr) does not ever end with a ;
Last edited by frrossk; Nov 12th, 2004 at 5:54 am. Reason: code tags:)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 5134 | Replies: 17
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC