Thread: can't find the error

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    14

    can't find the error

    I am a newbie to programming, i started with c programming as many people said it is a good idea to start with c or c++. Anyway, i was writing this code but i keep getting error on the last else. i looked everywhere i can't find the error. the message is not clear (or i don't understand what it means). can you look at this code and tell me what is wrong? thank you
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    /*SIMPLE PROGRAM FOR FINDING REAL ROOTS OF THE EQUATION: ax2+bx+c=0*/
     
    int main()
    {
     float a,b,c,x1,x;
     printf("enter a, b, c separated by space\n");
    
     scanf("%f%f%f",&a,&b,&c);
    
     if (a==0&&b==0)
    
        printf("No root"); 
    
     else if(a==0)
     
      
      printf("there is only one root %f",-c/b);
    
     else if ((b*b-4*a*c)<0) 
    
        printf("No root");
     
    else {
        x1=-b+((b*b-4*a*c)/2)2*a;   
    
        x=-b-((b*b-4*a*c)/2)2*a;
    
        printf(" X1 is %f, X is %f",x1,x);
    }
    getchar();
     
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    You are missing one * before 2.

  3. #3
    Registered User
    Join Date
    Sep 2015
    Posts
    14
    Quote Originally Posted by Satya View Post
    You are missing one * before 2.
    thank you, that was the mistake.

  4. #4
    spaghetticode
    Guest
    @endrick - when learning to program it's a good idea to also learn compiler messages. I know they look confusing and scary to a beginner at first sight - but a lot of them are pretty straight forward, and even if not, once you know how to read them, they are good help in spotting errors. I suggest next time you don't make do by stating "I get an error", but instead come up with the actual error message and let people help you understand it.

  5. #5
    Registered User
    Join Date
    Sep 2015
    Posts
    14
    thank your for the advice. i will

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cant find my error.
    By Moon River in forum C Programming
    Replies: 4
    Last Post: 09-20-2014, 02:17 PM
  2. one error....can't find it
    By ammanbesaw in forum C++ Programming
    Replies: 4
    Last Post: 12-13-2007, 10:36 AM
  3. STL find error with STL map
    By VirtualAce in forum C++ Programming
    Replies: 3
    Last Post: 08-20-2007, 01:23 PM
  4. Can't find error
    By shadowsora15 in forum C++ Programming
    Replies: 5
    Last Post: 05-26-2007, 04:00 AM
  5. Cant find the error
    By Coder87C in forum C Programming
    Replies: 8
    Last Post: 06-19-2005, 01:57 AM

Tags for this Thread