Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    37
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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	5	error C2143: syntax error : missing ';' before '{'	c:\users\owner\documents\visual studio 2008\projects\quad\quad\quad.cpp	17	quad
    Error	6	error C2447: '{' : missing function header (old-style formal list?)	c:\users\owner\documents\visual studio 2008\projects\quad\quad\quad.cpp	17	quad
    Error	7	error C2059: syntax error : 'else'	c:\users\owner\documents\visual studio 2008\projects\quad\quad\quad.cpp	21	quad
    Error	8	error C2143: syntax error : missing ';' before '{'	c:\users\owner\documents\visual studio 2008\projects\quad\quad\quad.cpp	22	quad
    Error	9	error C2447: '{' : missing function header (old-style formal list?)	c:\users\owner\documents\visual studio 2008\projects\quad\quad\quad.cpp	22	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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    37
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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
    •