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

Thread: programing help

  1. #1
    Join Date
    Dec 2006
    Posts
    4

    programing help

    I am taking a online c++ programing class. Since its online i have no real instructer to help me understand the course. Our finals are due friday and one of the programing problems on it has got me stuck. I would really appreciate it if some one on here would be willing to help me by either giving me pointers in the right direction or making the program for me its not that its hard i just dont have the materials needed to help me figure it out.

    heres the problem

    Create a program which will generate a 5x5 matrix of random generated numbers using a muti dimensional array. Your values should range from 1 to 100. You will need to display the array to the screen, then the program will display the max value for each row and the max value for the array.

    im shure it wouldnt take some one experinced to make something like this but i cant barly get a array with random numbers to work.

  2. #2
    Join Date
    Aug 2001
    Location
    Texas
    Posts
    645

    Re: programing help

    Post the code that you have.

    State what the problems are with your code. Be as specific as possible.

    (Use the code tags when you post the code to make it easier to read)

  3. #3
    Join Date
    Sep 2005
    Location
    United States
    Posts
    799

    Re: programing help

    While it is true that most of us here could write such a program easily, that is not the point.

    You aren't going to learn anything by us doing that.

    Surely, if you have gone over an entire semester of basic C++, you have covered multi-dimensional arrays, random numbers, loops, if-else statements, and basic functions. This is all you need to do this.

    Try to do it yourself, and come back later and ask questions if you get stuck.

    I am willing to bet you could at least write enough code to be able to declare a 5 x 5 array, even if you don't know what to do with it.

    Don't get overwhelmed. Take a deep breath, and start with this...
    Code:
    int main()
    {
       return 0;
    }
    And build off of that

    Also, on a side note, learning C++ in an online course is probably not a good idea. IMO, there is no substitute for having an actual human being teach you something, where you can ask questions and learn things in real time, instead of having to learn it yourself out of a book. The book is a good supplement to learn with, but you need someone readily available who you can ask questions.
    Last edited by dcjr84; December 6th, 2006 at 05:50 PM.
    Please rate my post if you felt it was helpful

  4. #4
    Join Date
    Dec 2006
    Posts
    4

    Re: programing help

    alright its not that i dont really know how to do any of this im just really pressed for time. I take online classes cause i work full time ive got more of a sob story but it dont matter. but heres what i got it dosnt work.

    #include <cstdlib>
    #include <ctime>
    #include <iostream>

    static const int conROWS = 5;
    static const int conCOLS = conROWS;

    int main(int argc, char* argv[])
    {
    int matrix[conROWS][conCOLS];
    int maxvalue;
    int r,c;

    srand(clock() + time()); //seed the random number generator

    //fill matrix with random values in range 1..100
    for(r=0; r<conROWS; r++)
    {
    for(c=0; c<conCOLS; c++)
    {
    matrix[r] = (rand() % 100) + 1;
    std::cout << matrix[r] << " ";
    };
    std::cout << std::endl;
    };


    //work out max row element
    for(r=0; r<conROWS; r++)
    {
    maxvalue= 0;
    for(c=0; c<conCOLS; c++)
    {
    if(matrix[r] > maxvalue)
    maxvalue = matrix[r];
    };
    std::cout << "Max value in row " << r << " is " << maxvalue;
    };

    //todo workout max value overall and display it
    return 0;
    };

    I hope this proves to you i know kinda what im doing and i would appreciate it of some one more experenced then me would get this up and running for me.

  5. #5
    Join Date
    Feb 2002
    Posts
    4,640

    Re: programing help

    Well, take the first element in the row, and compare it to all the others, keeping the max value. At the end, you should have the max element in that row.

    Now, take the max element in the first row, and compare it to the max value from all the other rows, keeping the max. At the end, you have the max value in the array.

    You just need to work out how to save the individual rows' max value (hint, single dimentional array might do it).

    Viggy

  6. #6
    Join Date
    Sep 2005
    Location
    United States
    Posts
    799

    Re: programing help

    Ok well, the majority of this looks fine. Some small errors.

    1) Don't put semicolons after your closing braces (except when declaring a class). Semicolons belong at the end of statements.
    Code:
    ...
    //fill matrix with random values in range 1..100
    for(r=0; r<conROWS; r++)
    {
       for(c=0; c<conCOLS; c++)
       {
          matrix[r] = (rand() % 100) + 1;
          std::cout << matrix[r] << " ";
       };
       std::cout << std::endl;
    };
    ...
    2) Seed the random number generator with the system time
    Code:
    ...
    srand( time( NULL ) ); //seed the random number generator
    ...
    3) In the double nested loop where you assign random numbers, you only specify one dimension...
    Code:
    ...
    matrix[r] = (rand() % 100) + 1;
    std::cout << matrix[r] << " ";
    You need to specify both dimensions, like this
    Code:
    ...
    matrix[r][c] = (rand() % 100) + 1;
    std::cout << matrix[r][c] << " ";
    ...
    Also, you code to return the maximum element in a row needs work. Take a look at it.
    Last edited by dcjr84; December 6th, 2006 at 07:03 PM.
    Please rate my post if you felt it was helpful

  7. #7
    Join Date
    Sep 2005
    Location
    United States
    Posts
    799

    Re: programing help

    I take online classes cause i work full time ive got more of a sob story but it dont matter.
    Not that I want to start an argument, but I work 40 hours a week and take 16-18 credit hours a semester at a 4 year University (and have never taken an online course), and I always manage to get my work done on time. Though I will admit, I have been rather stressed at certain times, but I am going to graduate in May nonetheless.
    Please rate my post if you felt it was helpful

  8. #8
    Join Date
    Dec 2006
    Posts
    4

    Re: programing help

    yea well try doing that ontop of taking care of your two dying parents being in and out of hospitals at all hours of the night .. you know **** it sorry i asked yall for help

  9. #9
    Join Date
    Sep 2005
    Location
    United States
    Posts
    799

    Re: programing help

    Quote Originally Posted by monolith1986
    yea well try doing that ontop of taking care of your two dying parents being in and out of hospitals at all hours of the night .. you know **** it sorry i asked yall for help
    I have already done that years ago when my parents died, so don't even try to pull that card out and make me look like an idiot.

    No need to get so upset. We were trying to help you, but not if you are going to get an attitude about it and use profanity.
    Last edited by dcjr84; December 7th, 2006 at 12:19 AM.
    Please rate my post if you felt it was helpful

  10. #10
    Join Date
    Dec 2006
    Posts
    4

    Re: programing help

    well then you know exactly how i feel (pulling no cards) and no you wernt helping you were being a smart *** telling me oh here start with int main and return 0 and work your way from there. then to say hey i can do this so you shouldnt get help maybe you should of just kept your opinion to yourself.

  11. #11
    Join Date
    Sep 2005
    Location
    United States
    Posts
    799

    Re: programing help

    Quote Originally Posted by monolith1986
    well then you know exactly how i feel (pulling no cards) and no you wernt helping you were being a smart *** telling me oh here start with int main and return 0 and work your way from there. then to say hey i can do this so you shouldnt get help maybe you should of just kept your opinion to yourself.
    Did you even read my last post where I helped you out by making all those corrections? Apparently not.

    then to say hey i can do this so you shouldnt get help
    Perhaps English is not your native language, so let me clarify.

    To quote myself...
    While it is true that most of us here could write such a program easily, that is not the point.

    You aren't going to learn anything by us doing that.

    Surely, if you have gone over an entire semester of basic C++, you have covered multi-dimensional arrays, random numbers, loops, if-else statements, and basic functions. This is all you need to do this.

    Try to do it yourself, and come back later and ask questions if you get stuck.
    Where in there does it say "then to say hey i can do this so you shouldnt get help"? Nowhere. I said you won't learn anything by us doing your homework for you, and you should try doing it yourself, and then come back and ask for help.

    You did not post any code at this point. You came on here saying "alright its not that i dont really know how to do any of this im just really pressed for time." , which is rather arrogant. People on here have jobs, and other things to do. We do not want, nor have the time, to do other people's homework assignments here. If you don't like that, go elsewhere.

    If you want help, like myself and Mr. Viggy were offering, I suggest you calm down and take a deep breath. If not, then bye bye.
    Last edited by dcjr84; December 6th, 2006 at 09:08 PM.
    Please rate my post if you felt it was helpful

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