Dismiss Notice

Psst... Ready to join TalkBass and start posting, make new friends, sell your gear, and more?  Register your free account in 30 seconds.

Who wants to debug my C++ program

Discussion in 'Off Topic [BG]' started by Matt Till, Sep 20, 2003.

  1. Matt Till

    Matt Till

    Jun 1, 2002
    Edinboro, PA
    First of all... I am sooooOOoO sorry about this, but this has been boggling my mind for days, it just doens't make any damn sense. I'm having errors on all of my cout<<""<<endl; lines and on my first { after my int main... here's the program so far...

    See text files in next post

    I hope this shows up right. And yes, I am asking you to do my homework. ;) But I would have asked the teacher about this anyway, but she's always really busy.
  2. Matt Till

    Matt Till

    Jun 1, 2002
    Edinboro, PA
    hmm... it's pasting weird... here...
  3. Matt Till

    Matt Till

    Jun 1, 2002
    Edinboro, PA
    DAMN IT! I don't know how to do this... I can't even display my program to you guys correctly. Ugh.
  4. I'll do it for you..

    I just need to get a compiler for my laptop ;)

    the only thing I can think of, is that you don't have #include "<"iostream ">" (without the "s of course) in your program...

    edit: you also forgot a couple of ';' in there, too
  5. also...

    cout << " (Number of Cheeseburgers?) " << cin >> nocb;
    cout << " (Number of Grilled Chicken Deluxe?) " << cin >> nogcd;
    cout << " (Number of Big Macs?) " << endl << cin >> nobm;
    cout << " (Number of Large French Fries?) " << endl << cin >> noff;

    what the hell are you doing there?

    those << should be ; ... you're not printing out a string or int that's called cin, so there should be no << there. understand?
  6. after reading over your program once more I noticed more stuff...

    there shouldn't be a ; after "int main() ", and you have an endl before cin, which makes the program look stupid while run.

    I've gotten it all perfect and compiling well, and can post the file here if you want, but won't you rather find the errors yourself? ;)

    have fun!
  7. It's been a while since i done c++ but everything the_bass said do was correct. I can get it to compile but i get linking errors when i try to build it for some reason.

  8. geshel


    Oct 2, 2001
    Yup you'll need to put the cin stuff on their own lines.

    Everytime you do an operation involving "<<" with cout, the return is a reference to cout again (so the next "<<" will get sent to it too.

    Doing this:

    cout << "foo" << cin >> x;

    is going to:

    - send "foo" to cout

    - send cin to cout! (not sure what this will do - if it compiles, likely it'
    ll either print the address of cin (which is just a global variable), or some status of the object)

    - try 
    to extract from cout (not cin!) into x

    I didn't think you could even use the >> operator on cout. That, plus the semicolon after main, makes me wonder how that program even compiles?

  9. Matt Till

    Matt Till

    Jun 1, 2002
    Edinboro, PA

    You da man bassy. I might need you to post that, but I'll try and work on it myself. I did add a ; after int main() and it still said "error on line 29" which would be the {

    I dunno, we'll see. I'll get back to you. Thanks again for the help and thanks for all the fish.
  10. Matt Till

    Matt Till

    Jun 1, 2002
    Edinboro, PA
    I have #include <iostream> and the int main(); right. But where to these ","'s belong?
  11. Matt Till

    Matt Till

    Jun 1, 2002
    Edinboro, PA
    Actually. If you could post up your version. I'd like to compare them. As I've learned with my programming problems in the past, it's always something little and stupid I'm doing. It probably is those commas wherever they go that's screwing me over. :(
  12. yebb, that's pretty much the same changes I did.
  13. Matt Till

    Matt Till

    Jun 1, 2002
    Edinboro, PA
    Thanks very much to all who contributed. I'm going to go see what I did wrong now. I'm sure this seems like child's play to you vets, but we all gotta start somewhere. :)
  14. Matt Till

    Matt Till

    Jun 1, 2002
    Edinboro, PA
    did you run that and it was fine? because I got this when I tried to compile it...

    p1.cpp: In function `int main()':
    p1.cpp:41: parse error before `<'

    I think you know where int main() is. I tried adding a semi colon, but then several more errors popped up. :(

    Line 41: cout << setw(22) << "===" << setw(12) < <"========" << setw(18) << "============" << endl;

    I have no idea what's wrong with this one.
  15. Phat Ham

    Phat Ham

    Feb 13, 2000
    It compiled and ran fine for me. I used g++. There should not be a ; after int main(). Maybe the inconsistent indentation at line 41 is messing something up, though I've never used a compiler that cared about indentation. What compiler are you using?
  16. Matt Till

    Matt Till

    Jun 1, 2002
    Edinboro, PA
    I'm not sure, it's on the server that I work in. To write the program I type "joe nameofprogram.cpp" and to compile I type "c++ nameofprogram.cpp" and then I type a.out and it runs the file.
  17. Matt Till

    Matt Till

    Jun 1, 2002
    Edinboro, PA
    OK, I obviously did something little and stupid because I pasted yours in directly and it runs fine. I don't know WHAT I did, but I'll figure that out. Thanks again.