Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Unknown error in c++

  1. Sep 19, 2010 #1
    after typing these following code
    when running this code
    error occurs,but the editor doesn't indicate me where's the problem
  2. jcsd
  3. Sep 19, 2010 #2


    User Avatar
    Science Advisor

    One obvious error is that there is no } to finish the main() subroutine. There may be others...
  4. Sep 19, 2010 #3


    Staff: Mentor

    Use [ code] and [ /code] (without the leading spaces) for your code.

    Code (Text):

    #include <iostream>
    using namespace std;
    int main()
       int deg;
       cout << "Enter the degree of the polynomial:" << endl;
       cin >> deg ;
       cout << "For the polynomial f(x)=";
       if (deg ==3)
          cout<<"For the polynomial f(x)=C1*x^3+C2*x^2+C3*x^1+C4, enter C1, C2, C3, C4 in order:";
       else if(deg==2)
          cout<<"For the polynomial f(x)=C1*x^2+C2*x^1+C3, enter C1, C2, C3 in order:";
       else if (deg==1)
          cout<<"For the polynomial f(x)=C1*x+C2, enter C1, C2 in order:";

       return 0;
    As phyzguy points out, you're missing the final brace at the end of main.

    There is another error as well - you are missing an else clause at the end of your if ... else if clauses.

    Also, you apparently want the program user to enter the coefficients of the various powers of x, but you don't have input statements to do this, and you don't have variables declared to hold c1, c2, etc.
  5. Sep 21, 2010 #4
    thx a lot,problem fixed finally
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook