Need Help With Arrays...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vegiitto
    New Member
    • Jul 2007
    • 12

    Need Help With Arrays...

    Okay so I'm at the University of Alberta testing out programs (I'm 15 btw with a year of programming and no C++). Anyway we have to do this program where it asks the user to input 10 numbers (All on different lines) and then put all those numbers on a single line and then average out all the numbers. Now we have to use an array using a while or for loop (Well they want me to do both...) now I've never done any array type coding so this is obviously where I'm getting stuck at.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Arrays are covered in in any introductory book on C or C++.

    I can only help you with specific problems.

    Please read the posting guidelines.

    Comment

    • Vegiitto
      New Member
      • Jul 2007
      • 12

      #3
      Okay help me with the code so the program asks and takes into an array the 10 numbers that he/she puts in.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        OK. Show me what you have so far.

        Comment

        • Vegiitto
          New Member
          • Jul 2007
          • 12

          #5
          [CODE=cpp]int num;
          num = 0;
          while (num < 3) {
          cout << "Enter a number: ";
          cin >> num[0];
          cout << "The 0th element in the array is " << num[0];
          num = num + 1;
          }[/CODE]

          I know it's all wrong...but like I said I have never done this and have no idea.
          Last edited by r035198x; Aug 1 '07, 07:21 PM. Reason: Added code tags. Please don't forget them next time

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by Vegiitto
            int num;
            num = 0;
            while (num < 3) {
            cout << "Enter a number: ";
            cin >> num[0];
            cout << "The 0th element in the array is " << num[0];
            num = num + 1;
            }

            I know it's all wrong...but like I said I have never done this and have no idea.
            You have done arrays in class right? Why not go through your notes first or an arrays tutorial before you try this again?

            Comment

            • Vegiitto
              New Member
              • Jul 2007
              • 12

              #7
              no that's the thing...I haven't done arrays or C++...so I have no idea how to do them

              Comment

              • r035198x
                MVP
                • Sep 2006
                • 13225

                #8
                Originally posted by Vegiitto
                no that's the thing...I haven't done arrays or C++...so I have no idea how to do them
                Go through this then give your program another short.

                Comment

                • Vegiitto
                  New Member
                  • Jul 2007
                  • 12

                  #9
                  Okay thanks...that helped with declaring the array but did nothing towards how I can ask the user 10 times to put a number then take it into the array

                  Comment

                  • r035198x
                    MVP
                    • Sep 2006
                    • 13225

                    #10
                    Originally posted by Vegiitto
                    Okay thanks...that helped with declaring the array but did nothing towards how I can ask the user 10 times to put a number then take it into the array
                    Refer back to your previous problem. The one with the while and if elses.

                    Comment

                    • Vegiitto
                      New Member
                      • Jul 2007
                      • 12

                      #11
                      Is this the right start though?

                      int num[9];

                      while (num < 10) {
                      cout << "Enter a number: ";
                      cin >> num[0];
                      cout << "The 0th element in the array is " << num[0];
                      num = num + 1;
                      }

                      If not could you help out on what to put and where

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        Originally posted by Vegiitto
                        Is this the right start though?

                        int num[9];

                        while (num < 10) {
                        cout << "Enter a number: ";
                        cin >> num[0];
                        cout << "The 0th element in the array is " << num[0];
                        num = num + 1;
                        }

                        If not could you help out on what to put and where
                        That won't help you to get this done on your own in the future.
                        All those things that were said in class really were important. For example, the fact that variables have one type. So you can't use the same variable to store both an int and an array. Do refer back to that link I gave you and see how the variables were being defined.

                        Comment

                        • Vegiitto
                          New Member
                          • Jul 2007
                          • 12

                          #13
                          You don't realize that I wasn't in a class with this like I've stated many times before this. I have not learned this stuff and am asking for help...this is not a class

                          Comment

                          • r035198x
                            MVP
                            • Sep 2006
                            • 13225

                            #14
                            Originally posted by Vegiitto
                            You don't realize that I wasn't in a class with this like I've stated many times before this. I have not learned this stuff and am asking for help...this is not a class
                            Yes, sometimes I'm slow to understand some things. Thanks for repeating.
                            I hope you are going over that link again now. It even has an example that covers more than half of what you want to do here.

                            Comment

                            • Vegiitto
                              New Member
                              • Jul 2007
                              • 12

                              #15
                              Don't know if that was sarcasm or not...but yes I'm going over it

                              Comment

                              Working...