swapping code

This is a discussion on swapping code within the C++ Programming forums, part of the General Programming Boards category; I have to write a block of code that swaps the input !! Be gentle on me I am new ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    21

    Smile swapping code

    I have to write a block of code that swaps the input !!
    Be gentle on me I am new at this!!

    int num1, num2;
    cout << "Please enter two values:";
    cin >> num1, num2

    This is where I get lost, I have been told you can use a swap function??!!

    cout << "Number " << num1 << "\nnum2: <<num2<<endl;
    is what my output has to look like

    Any kind soul that has some direction for me....I would greatly appreciate it!!!!

  2. #2
    Registered User biosx's Avatar
    Join Date
    Aug 2001
    Posts
    230
    Can you at least try?

    I'll give you a hint... Use a temporary variable as storage.

  3. #3
    In The Light
    Join Date
    Oct 2001
    Posts
    598

    a little more

    swap(&a, &b);

  4. #4
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    that swapping thing works? if he went swap(&num1, &num2) it would swap it? weird...

    i always do

    int temp;

    temp = num1;
    num1 = num2;
    num2 = temp;

    that swaps it
    Paro

  5. #5
    Unregistered
    Guest

    same thing paro

    I'm sure he is talking about a use defined function, without giving away too much detail

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    21

    Smile

    I thank you all for all the input. My teacher is great but sometimes he has us do something before we actually learn it. I looked through my book and the c++ for dummies and they both look very different so I guess that is what confused me....Thanks again!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 11:20 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

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