need help plz

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bigj0410
    New Member
    • Feb 2007
    • 25

    #16
    Originally posted by sicarie
    Well, I'd start out with the shell:

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    
        return 0;
    }
    and then I would put my algorithm inside


    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        //  create matrix[10][10]
        // for each i in matrix [1][i]
            // get random number between 1 and 100
            // matrix[1][i] = random number
        // for each i in matrix [2][i]
            // get random number betwee 100 and 200
            // matrix[2][i] = rand
        /// and on to matrix [10][i]
        return 0;
    }
    Then I would go through and start breaking that algorithm down - into statements that could be in a single line, and then try to turn it into code


    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        //  create matrix[10][10]
        int matrix[10][10];
        int tmp_rand;
        // for each i in matrix [1][i]
        for (int i = 0; i < 10; i++) {
            // get random number between 1 and 100
            /* I'm not going to give this away, but I'm pretty sure you could figure it out */
            // matrix[1][i] = random number
        // for each i in matrix [2][i]
            // get random number betwee 100 and 200
            // matrix[2][i] = rand
        /// and on to matrix [10][i]
        }
        return 0;
    }
    and so on. This way it starts out as a working template (even though it doesn't do anything, it will compile), and builds up from there - and my code will be commented!

    Does that make sense? Help at all?


    yea it does make a bit sense...it does help...thx dawg (thumbs up)....but i'll still ask for help though :)

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #17
      Originally posted by Bigj0410
      yea it does make a bit sense...it does help...thx dawg (thumbs up)....but i'll still ask for help though :)
      Absolutely - we're more than happy to help.

      And, just in case you didn't see (if you didn't you shouldn't worry about it - I'm sure it will come to you when you start programming), there is another optimization you can make in the algorithm.

      Comment

      • Bigj0410
        New Member
        • Feb 2007
        • 25

        #18
        Originally posted by sicarie
        Absolutely - we're more than happy to help.

        And, just in case you didn't see (if you didn't you shouldn't worry about it - I'm sure it will come to you when you start programming), there is another optimization you can make in the algorithm.
        really? like what?

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #19
          Originally posted by Bigj0410
          really? like what?
          Well, at least in my algorithm (as yours only deals with half first). Just think of ways to keep yourself from having to write more code.

          Comment

          • Bigj0410
            New Member
            • Feb 2007
            • 25

            #20
            Originally posted by sicarie
            Well, at least in my algorithm (as yours only deals with half first). Just think of ways to keep yourself from having to write more code.

            ok that sounds good...btw...i' m starting to understand the program u wrote...thx again ;)

            Comment

            • sicarie
              Recognized Expert Specialist
              • Nov 2006
              • 4677

              #21
              Originally posted by Bigj0410
              ok that sounds good...btw...i' m starting to understand the program u wrote...thx again ;)
              Good, that was the point. And by the way - I didn't write it - you are going to. You did come up with the algorithm and most of the code. You know what you're doing, you just don't think you do yet.

              Definitely post again if you get stuck!

              Comment

              • Bigj0410
                New Member
                • Feb 2007
                • 25

                #22
                ok ...i was going over this plus reading other things on arrays and etc which then i got confused and this is wut i came up with so far
                btw...if u don't mind i used your variables

                #include <iostream>
                using namespace std;

                int main()
                {
                int matrix[10][10]
                int tmp_rand;
                for (int i = 0; i < 10; i++);
                { matrix[1][i] = (1 < i < 100);

                Comment

                • sicarie
                  Recognized Expert Specialist
                  • Nov 2006
                  • 4677

                  #23
                  Originally posted by Bigj0410
                  ok ...i was going over this plus reading other things on arrays and etc which then i got confused and this is wut i came up with so far
                  btw...if u don't mind i used your variables

                  #include <iostream>
                  using namespace std;

                  int main()
                  {
                  int matrix[10][10]
                  int tmp_rand;
                  for (int i = 0; i < 10; i++);
                  { matrix[1][i] = (1 < i < 100);
                  I dont' mind at all. Um, ok, I think you're trying to do too much at once. Let's break that up into two steps:

                  1) get random number between 1 and 100
                  2) assign number to matrix[][]

                  How would you do the first?

                  Comment

                  • Bigj0410
                    New Member
                    • Feb 2007
                    • 25

                    #24
                    Originally posted by sicarie
                    I dont' mind at all. Um, ok, I think you're trying to do too much at once. Let's break that up into two steps:

                    1) get random number between 1 and 100
                    2) assign number to matrix[][]

                    How would you do the first?
                    the first part i remember from math that if a number is between two numbers ...i assume thats wut u do in c++ so i put it there (shrugs my shoulders)
                    but the matrix thing its coming to me now

                    Comment

                    • sicarie
                      Recognized Expert Specialist
                      • Nov 2006
                      • 4677

                      #25
                      Originally posted by Bigj0410
                      the first part i remember from math that if a number is between two numbers ...i assume thats wut u do in c++ so i put it there (shrugs my shoulders)
                      but the matrix thing its coming to me now
                      Good!

                      Well, here I'm also assuming you can get a random number in the first place - let's start there, how would you do that?

                      Comment

                      • Bigj0410
                        New Member
                        • Feb 2007
                        • 25

                        #26
                        Originally posted by sicarie
                        Good!

                        Well, here I'm also assuming you can get a random number in the first place - let's start there, how would you do that?

                        ihave no clue ...at first i thought i knew it but i don't sorry :(..i really suck at this

                        Comment

                        • sicarie
                          Recognized Expert Specialist
                          • Nov 2006
                          • 4677

                          #27
                          Originally posted by Bigj0410
                          ihave no clue ...at first i thought i knew it but i don't sorry :(..i really suck at this
                          Ah! Ok, sorry, that was my fault, I was trying to push you to do something you didn't know. It's ok, check this link for rand() . That should start to clear up a lot more.

                          Comment

                          • Bigj0410
                            New Member
                            • Feb 2007
                            • 25

                            #28
                            Originally posted by sicarie
                            Ah! Ok, sorry, that was my fault, I was trying to push you to do something you didn't know. It's ok, check this link for rand() . That should start to clear up a lot more.
                            ok its begining to look ok...so how would i input this in the program?

                            Comment

                            • sicarie
                              Recognized Expert Specialist
                              • Nov 2006
                              • 4677

                              #29
                              Originally posted by Bigj0410
                              ok its begining to look ok...so how would i input this in the program?
                              Well, that's what I'm asking you - there are examples in the article. Just worry about putting in one. How would you assign a random number from rand() to tmp_rand?

                              Comment

                              • Bigj0410
                                New Member
                                • Feb 2007
                                • 25

                                #30
                                Originally posted by sicarie
                                Well, that's what I'm asking you - there are examples in the article. Just worry about putting in one. How would you assign a random number from rand() to tmp_rand?
                                ?? (shrugs my shoulders)

                                Comment

                                Working...