Thread: Still having problems...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    30

    Still having problems...

    I tried the changes but it still doesnt work, but now im only down to one error, parse error on line 17, but i only have 16 lines, here's the code so far:
    Code:
    #include <iostream.h>
    
    class Exchg {
          public:
                 void exchange (int& a, int& b) {
                      int temp = a;
                      a = b;
                      b = temp;}
    int main () {
    Exchg e
    int num1 = 56;
    int num2 = 111;
    cout << "the two numbers: " << num1 << "," << num2 << "..." << endl;
    e.exchange (num1, num2);
    cout << "... are now exchanged: " << num1 << "," << num2 << endl;
    return 0; }
    ps i meant to say the book wasnt that good, maybe you can suggest a better one?
    Last edited by Gamma; 04-14-2002 at 04:40 PM.

  2. #2
    Try:

    Code:
    #include <iostream.h>
    
    class Exchg 
    {
           public:
                 void exchange (int& a, int& b) {
                      int temp = a;
                      a = b;
                      b = temp;
                 }
    } // REMEMBER TO CLOSE YOUR CLASS
    
    main () {
    Exchg e
    int num1 = 56;
    int num2 = 111;
    cout << "the two numbers: " << num1 << "," << num2 << "..." << endl;
    e.exchange (num1, num2);
    cout << "... are now exchanged: " << num1 << "," << num2 << endl;
    }
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    30
    thanks that solved the problem!

  4. #4
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Code:
    class Exchg 
    {
           public:
                 void exchange (int& a, int& b) {
                      int temp = a;
                      a = b;
                      b = temp;
                 }
    }; /// and don't forget the closing ; either :)
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  5. #5
    It has to have a closing ";"?
    Thanks! I didn't know that!
    I am suprised my compiler hasn't complained about it however, because u use classes somewhat often.
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM