Need help fixing a few issues

I am very new (2 days) to C and I am working on a "quadratic equation form converter". If you forget what a quadratic equation is, it's probably because it's taught in high school.

There are a few things that I want to fix:

First of all, when the script restarts, it starts all the way from the beginning, is there a way to have it only go back to, say, the line of dots?

Secondly, why won't it stop at "getchar();" and why is it, the first repeat it says "option" has an incorrect value and the second time it prompts for user input?

Finally, is there a way to reduce the lenght of the floating point numbers depending on how long they are, for example, leaving 5.000000 at 5 and 3.333333 at 3.33?

I am using DEV C++ and I am working with C not C++. Here is my source code:

[code]#include
#include

#define CANONIC "f(x)=A(x-H)^2+K"
#define GENERAL "f(x)=Ax^2+Bx+C"
#define FACTORED "f(x)=A(x-X1)(x-X2)"

char option;
float a;
float b;
float c;
float h;
float k;
float x1;
float x2;

main()
{
option = '1';
printf ("===[...]==
QUADRATIC FUNCTION FORM CONVERTER
==[...]==");
printf ("

This program converts the form of
quadratic equations. Please follow
the instructions carefully, a typo");
printf ("
could cause the program to crash.

..[...]...

");
printf ("Chose the form you are converting
from, by typing in the number of
your option and hitting return.

");
printf ("[1] Canonic: ");
printf (CANONIC);
printf ("
[2] General: ");
printf (GENERAL);
printf ("
[3] Factored: ");
printf (FACTORED);
printf ("

Option: ");
scanf ("%c", &option);

if (option=='1')
{
printf ("
You have chosen to convert from the
canonic form: ");
printf (CANONIC);
printf ("
Please enter the values of A, H and
K, seperated by commas, e.g. 12,34,9

");
scanf ("%f,%f,%f",&a,&h,&k);
printf ("
You chose to convert f(x)=%f(x-%f)^2+%f

",a,h,k);
printf ("Hit return to restart
");
getchar();
main();
}
else
{
if (option=='2')
{
printf ("
You have chosen to convert from the
general form: ");
printf (GENERAL);
printf ("
Please enter the values of A, B and
C, seperated by commas, e.g. 12,34,9

");
scanf ("%f,%f,%f",&a,&b,&c);
printf ("
You chose to convert f(x)=%f(x)^2+%fx+%f

",a,b,c);
printf ("Hit return to restart
");
getchar();
main();
}
else
{
if (option=='3')
{
printf ("
You have chosen to convert from the
factored form: ");
printf (GENERAL);
printf ("
Please enter the values of A, X1 and
X2, seperated by commas, e.g. 12,34,9

");
scanf ("%f,%f,%f",&a,&x1,&x2);
printf ("
You chose to convert f(x)=%f(x-%f)(x-%f)

",a,x1,x2);
printf ("Hit return to restart
");
getchar();
main();
}
else
{ printf ("This is not a valid option

");
printf ("Hit return to restart
");
getchar();
main();
}
}
}
printf ("Hit return to restart
");
getchar();
main();
return(0);
}[/code]
[...] means I left out a bit

The conversion part of it is not done yet. Basically it converts from one of the three forms to the other two.

Thanks for your help in advance
-----
Shant
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories