CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,925

    Re: Need Help with 2D arrays and functions

    Code:
    int rows = atoi(argv[2]);
    int cols = atoi(argv[4]);
    What happens if argc < 5? You haven't tested for the error conditions mentioned in the assignment.

    Your fillArray sets the initial values. But your showArray also sets values in the array! Shouldn't showArray just show the values and not also change values?

    Code:
    tmpfile.getline(line, 10, ' ');
    This will read a line from the file stream associated with tmpfile. But you don't open a file anywhere! From where did you get this code for find_greatest_product? Its based upon a 20x20 array read from a file - whereas for your program the size of the array is entered on the command line and fillArray sets the values of the array rather than reading from a file! You need to get rid of this code that reads from a file and change the loop conditions to refer to the rows and cols variables passed to the function as indicated in Paul's post.

    where to insert cout statements so that the function will output the max product based on the user input?
    When the function has finally calculated the maximum value!
    Last edited by 2kaud; June 1st, 2013 at 07:04 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured