The Student Room Group

urgent C programming help

Hi i am trying to create a c program to solve quadratic equations and i cant get my code to compile. I dont know whats wrong with it, and its a very long code. I think theres something wrong with my switch and was hoping that i could pm the code to someone and they could try and run it and tell me were its going wrong. is anyone available?
Reply 1
If it's failing to compile, then presumably you have some kind of console output with error messages. Posting those, along with the relevant blocks of code, would be a good place to start.
Reply 2
Original post by Planto
If it's failing to compile, then presumably you have some kind of console output with error messages. Posting those, along with the relevant blocks of code, would be a good place to start.


i have just sorted that, now i am trying to program this quadratic equation solver to deal with complex coefficients. i have a question. is there any way in which i can define say I st I*I=-1 in such a way that when i am requried to input numbers and i input I the c compiler will recognise it.
Reply 3
I'm not sure what you mean. You can't have the C compiler recognise anything at runtime since the compiler is no longer involved by that point. If you just want to validate the input so that the program will only accept I such that I^2 = -1 then you can just check that this holds with an if statement after the input, only continuing once the constraint holds.
Reply 4
what error message are you getting?
Reply 5
Original post by REEPER
i have just sorted that, now i am trying to program this quadratic equation solver to deal with complex coefficients. i have a question. is there any way in which i can define say I st I*I=-1 in such a way that when i am requried to input numbers and i input I the c compiler will recognise it.


you're trying to define an imaginary number? that method won't work. Try doing

float x,y;
printf("enter the real value\n");
scanf("%f",&x);
printf("enter the imaginary value\n");
scanf("%f",&y);

and then define the the relationship between real and imaginary every time you attempt to manipulate them.

edit: the scanf's might be wrong syntax slightly, its been a while since I used them
edit 2: you should probably also use floats.
(edited 13 years ago)
Reply 6
I thought of another way:

If you define

logical imaginary = false;
char test;
float y;

then
scanf("%f %c",y, test);

if(y==i) imaginary = true;

then use

if(imaginary)

every time to try and manipulate the number.

It would be a bit more fiddly, but your IO would be neater.

Quick Reply

Latest

Trending

Trending