I need basic C help here
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: I need basic C help here

  1. #1
    Join Date
    Jun 2007
    Posts
    9

    I need basic C help here

    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. (I am trying to write the quadratic equation that finds the real roots)

    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. #2
    Join Date
    Jun 2006
    Posts
    644

    Re: I need basic C help here

    u cannot just write if...anywhere in the file you would like it to be...

    In your case it has been written outside the main function block....Put it in main or any other function and then call the function from main....
    Bhushan

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center