The online racing simulator
A little help please
(6 posts, started )
A little help please
Hi

Im very new to programming and i just need a little help

This is a little (very basic) app that solves quadratic equations

I want to add a bit on to it, but my basic skills are letting me down. Where it says "No Solution", i would like to add a bit where it says "No solution, would you like another go?" then if they say yes, it goes to the beginning and if they say no, the program exits.

I hope i explained it well enough Thanks


#include <stdio.h>
#include <math.h>
int main()
{
//declare variables
double a,b,c,x1,x2,d;

//read inputs
printf("What number represents a? "); scanf("%lf",&a);
printf("What number represents b? "); scanf("%lf",&b);
printf("What number represents c? "); scanf("%lf",&c);

//calculate x1,x2
d=b*b-4*a*c;
if(d>=0)
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("x1=%d\n",x1);
printf("x2=%d\n",x2);
}
else
{
printf("No solution\n");
}
}

Untested, but baring any typos, it should be fine. Things to note; 'yes' is case sensitive here, fgets is used in place of gets to avoid an overflow. Because of this, we use 'stdin' is the file descriptor for standard input.
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
//declare variables
double a,b,c,x1,x2,d;

unsigned char solution = 0;

while (solution == 0)
{
//read inputs
printf("What number represents a? ");
scanf("%lf",&a);
printf("What number represents b? ");
scanf("%lf",&b);
printf("What number represents c? ");
scanf("%lf",&c);

//calculate x1,x2
d=b*b-4*a*c;
if(d>=0)
{
x1=(-b+sqrt(d))/(2*a);
x2=(-b-sqrt(d))/(2*a);
printf("x1=%d\n",x1);
printf("x2=%d\n",x2);
}
else
{
printf("No solution, do you wish to try again?\nPlease enter 'yes' to retry.\n");
char input[6];
memset(input, 0, 6);
fgets(input, 6, stdin);
if (strncmp(input, "yes", 6) == 0)
solution = 1;
}
}

printf("Goodbye!\n");
return 0;
}


Thanks alot Very much appreciated
Hi again,

I need help again, but this time its HTML help.

How do I get the <button> command to link to another page. I have looked at a few websites but I can't find much on it.

Thanks


EDIT: I found out how to do it

<input
type = "button"
onclick = "window.location='http://www.somewhere.com/';"
value = "Click me" />

Something like that should do it.

Edit: Just thinking, for a non-JavaScript version you could do something like this:


<form action="http://www.somewhere.com/">
<input type="submit" value="Click me" />
</form>

Quote :
Edit: Just thinking, for a non-JavaScript version you could do something like this:


<form action="http://www.somewhere.com/">
<input type="submit" value="Click me" />
</form>


Yeah, i done it this way

A little help please
(6 posts, started )
FGED GREDG RDFGDR GSFDG