Solving Unknown Error in C++ Code

  • Context: Comp Sci 
  • Thread starter Thread starter SOHAWONG
  • Start date Start date
  • Tags Tags
    C++ Error
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 2K views
SOHAWONG
Messages
16
Reaction score
0
after typing these following code
#include <iostream>
using namespace std;
int main()
{int deg;

count << "Enter the degree of the polynomial:" << endl;
cin >> deg ;
count << "For the polynomial f(x)=";
if (deg ==3)
{
count<<"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)
{
count<<"For the polynomial f(x)=C1*x^2+C2*x^1+C3, enter C1, C2, C3 in order:";
}
else if (deg==1)
{
count<<"For the polynomial f(x)=C1*x+C2, enter C1, C2 in order:";
}

return 0;

when running this code
error occurs,but the editor doesn't indicate me where's the problem
 
Physics news on Phys.org
One obvious error is that there is no } to finish the main() subroutine. There may be others...
 
Use [ code] and [ /code] (without the leading spaces) for your code.

Code:
#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.
 
thx a lot,problem fixed finally