Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: I need C help writting a program

1. ## I need C help writting a program

Code:
#define _CRT_SECURE_NO_WARNING
#include <stdio.h>
#include <math.h>
void main(void)
{
float a,b,c;
printf("Enter A \n");
scanf("%f",&a);
printf("Enter B \n");
scanf("%f",&b);
printf("Enter C \n");
scanf("%f",&c);
}
if(A==0)
{
x=-c/b;
printf("%f",x);
}
else
{
disc = b*b-4*a*c
if(disc==0)
{
x=-b/2a;
printf("%f",x);
}
else
{
if(disc>0)
{
x1=(-b+sqrt(disc))/(2*a);
x2=(-b-sqrt(disc))/(2*a);
printf("%f %f", x1, x2)
}
else
printf("No real roots");
}
}
I get 7 errors when I try to excute this...how would I go about making this work. I am a bit new to C.

Errors:
Code:
Error	4	error C2059: syntax error : 'if'	c:\users\owner\documents\visual studio 2008\projects\quad\quad\quad.cpp	16	quad
Error	10	error C2059: syntax error : 'bad suffix on number'	c:\users\owner\documents\visual studio 2008\projects\quad\quad\quad.cpp	26	quad

• Its trying to interpret the if and else as individual functions, which of course have invalid signatures (not to mention they use construct names). Move that into the main method.

Next, A is undefined, I'm thinking its supposed to be a.
And there are a few others that are undefined, the first is disc, second is x, third is x1 and final is x2. Remember in c that these all need to be predeclared.

Things like 2a and -c won't work either, you'll need to specify it as 2 * a and c * -1 (or ~c + 1) respectively. I'm pretty certain about the -c one not working, though it has been awhile since I've used C.

• Thank you, you were a big help!

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•