Help sorting out errors

This is a discussion on Help sorting out errors within the C++ Programming forums, part of the General Programming Boards category; OK I've just wrote something to fill some time, and I thought I had done it all right, but when ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    10

    Help sorting out errors

    OK I've just wrote something to fill some time, and I thought I had done it all right, but when I try compile it, it gives some errors, but the errors don't make much sense to me really. It's giving error messages like ' and (each.

    I'm pretty new so I have no idea what they're on about so I was hoping someone on here could help me.

    Code:
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    
    using namespace std;
    
    int main (int argc, char *argv[])
    {
    cout << "Works out two values of X in Quadratic Formulas (ax^2+bx+c=0)" << endl;
    cout << "Integers only" << endl;
    
    //Declare A,B,C,negative B, answer to both top and bottom halfs, number to be square rooted and the SQRT.
    //Also declares answers.
    int A;
    int B;
    int NegB;
    int C;
    int TopHalfP;
    int TopHalfN;
    int BottomHalf;
    int InRoot;
    int Root;
    int AnswerP;
    int AnswerN;
    
    //Put values for A.B & C into the program.
    cout << "Enter A" << endl;
    cin >> A;
    cout << "Enter B" << endl;
    cin >> B;
    cout << "Enter C" << endl;
    cin >> C;
    
    //Work out Negative B, the number to be SQRTed, the SQRT and the numbers to be divided
    NegB = B*-1;
    InRoot = (b*b)-(4*A*C);           // Gives ' and (each
    Root = sqrt(InRoot);                 //Gives call
    TopHalfP = NegB+Root;
    TopHalfN = NegB-Root;
    BottomHalf = 2*A;
    AnswerP = TopHalfP/BottomHalf;
    AnswerN = TopHalfN/BottomHalf;
    
    //Displays answers
    cout << "The answers for X are:" << endl;
    cout << AnswerP << endl;
    cout << "And" << endl;
    cout << AnswerN << endl;
    
    cout << "Press ENTER to continue..." << endl;
    cin.get();
    return 0;
    }
    That's the source and the errors on lines 39 and 40 are in notes at the side.

    It also gave some errors on lines in the hundreds, though this only gets to about 60 lines. I've put them in the image.

    If anyone could help with any of these it would be great.
    Attached Images Attached Images  

  2. #2
    Registered User HaLCy0n's Avatar
    Join Date
    Mar 2003
    Posts
    77
    On line 39:
    Code:
    InRoot = (b*b)-(4*A*C);           // Gives ' and (each
    There is no such variable "b". You probably wanted to use B.

    For the error you get on the line with sqrt(), there are 3 types that sqrt() will take, float, double, and long double. Pick one to cast your int to and it will be fine. Also, since you are using integers, remember that you are going to lose any decimals from the sqrt and division that take place.

  3. #3
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Code:
    InRoot = (b*b)-(4*A*C);           // Gives ' and (each
    there is no variable b. guess you mean B.

    Code:
    Root = sqrt(InRoot);       //Gives call
    there is no function sqrt() that takes an int as an argument -> the compiler dosn't know if it should convert it to a double or a float.
    declare inRoot as a double or a float.
    Kurt

    EDIT: far too slow today.

  4. #4
    Registered User
    Join Date
    Jul 2006
    Posts
    10
    Oh yeah, thanks a lot dude.

    It's compiled now and works. Soon as it prints the two answers though it shuts down the window. I thought cin.get(); should have meant you had to press something before it would continue, but obviously not.

    If anyone knows why it's shutting down right after that would help, but for now I'll just put in a 5 second sleep though.

    Thanks again for the help dude.

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,579
    *sigh*

    place cin.ignore() before the last get()
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Registered User
    Join Date
    Jul 2006
    Posts
    10
    Lol, sorry. I said I'm new to it, should have expected the questions to be simple.

    And thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 04:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 11:50 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 03:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. errors in class(urgent)
    By ayesha in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2001, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21