small error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomana123
    New Member
    • Oct 2008
    • 7

    small error

    Code:
    //Lab 9 Problem 3 program that allows user find mass of a particle
    #include <iostream>
    using namespace std;
    int main()
    {//defining variables
    float m, v, count;
    char exit_variable;
    cout<<"This is a programme to determine the mass of a particle";
    v = 0.2;
    while (v<=0.9)
    {m=1/(sqrt(1-(v*v)));
    cout<<"   when v is"<<v;
    cout<<"\nThe mass of the particle is"<<m;
    v=v+.1;
    }
    cout<<"Press any key to exit";
    cin>>exit_variable;
    }
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    When you are asking a question, please post any compiler errors you are getting, what your program is supposed to do, and what it is doing instead. You need to learn how to debug your own programs. Please follow the Posting Guidelines.
    Thanks.

    Comment

    • archonmagnus
      New Member
      • Jun 2007
      • 113

      #3
      I do see a few errors in your code. First, the "sqrt" function is defined in the "cmath" library. Otherwise you have no function declaration for the "sqrt" function and the compiler complains that it can't find the function to use. In otherwords, add the preprocessor directive:
      [code=cpp]
      #include <cmath>
      [/code]

      Second, check the line:
      [code=cpp]
      ...
      cout<<" when v is"<;<v;
      ...
      [/code]
      You are missing the correct binary operator "<<" for "cout" (i.e. remove the extraneous semi-colon). The line should read:
      [code=cpp]
      ...
      cout<<" when v is"<<v;
      ...
      [/code]

      Those minor edits should fix your code. I hope that helps.

      Comment

      Working...