| | |
Complex Numbers
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 12
Reputation:
Solved Threads: 0
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);
}
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);
}
•
•
Join Date: Mar 2004
Posts: 1,620
Reputation:
Solved Threads: 51
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...
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
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...
C Syntax (Toggle Plain Text)
Welcome to the Calculator Program. Would you like to Add, Subtract, Divide, or Multiply (A,S,D,M)? You chose to _ Please enter in your 1st Number: __ Please enter in your 2nd Number: __ Your answer is: ____ 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
•
•
Join Date: Nov 2004
Posts: 12
Reputation:
Solved Threads: 0
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);
}
#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);
}
>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?
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
>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.
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
•
•
Join Date: Nov 2004
Posts: 12
Reputation:
Solved Threads: 0
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
{
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
I assume #include <stdio.h>
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 ;
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:)
![]() |
Similar Threads
- Help! Convert pixel array of complex numbers to image. (Java)
- Trouble writing code for arithmetic calculations of complex numbers (C++)
- Code Snippet: multiply of complex numbers matrix (C++)
- Complex Numbers (C++)
- Need Help with complex numbers (C++)
- Help on Complex Number Calculator (C)
Other Threads in the C Forum
- Previous Thread: Compile Help!
- Next Thread: How to print data in JPG or BMP by C?
Views: 5134 | Replies: 17
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






