Need help with this problem.

This is a discussion on Need help with this problem. within the C++ Programming forums, part of the General Programming Boards category; I'm having pretty big problems with these class assignments.. Could someone please help me? It's killing me.. Change the following ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    4

    Need help with this problem.

    I'm having pretty big problems with these class assignments.. Could someone please help me? It's killing me..

    Change the following program to pass two parameters to the function multiply and return a result from it. Make the global variables local to main.

    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    // the following line is your function template
    // change it as needed
    void multiply();
    
    // the following two lines are global variables. 
    // Make them local to main and pass them back and
    // forth to/from the function multiply
    
    int x, y;  // global values that pass values in
    int result; // global value that returns the result
    
    
    int main ()
    {
       
       cout << "Enter two numbers\n";
       cin >> x >> y;
    
       multiply();
    
       cout << "The product is " << result << endl << endl;
    
       system ("PAUSE");
       return 0;
    }
    
    void multiply()
    {
      result = x * y;
      return;
    }

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Code:
    #include <iostream>
    //#include <string> This isn't needed
     
    using namespace std;
    
    int multiply(int x, int y);
    
    int main ()
    {
       int x, y, result;
       cout << "Enter two numbers\n";
       cin >> x >> y;
    
       result = multiply(x,y);
    
       cout << "The product is " << result << endl << endl;
    
       system ("PAUSE");
       return 0;
    }
    
    int multiply(int x, int y)
    {
      return x*y;
    }
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    You know. That almost sounded like a question from an exam. Nah it couldn't have been.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    It's a lot like this other thread though
    Rewrite using functions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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