Thread: beginner

  1. #16
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    if you want the numbers 1-10 in the array and you don't want to do it this way

    int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

    you can do it this way

    for (i=0, i<10, i++)
    {
    list[j] = i;
    };

    but the latter will put the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 in your array. To get 1-10 in the array using the latter format you can change the value of i so it ranges from 1 and <= 10 or from 1 to < 11. Or you can leave the range of i as you have it and change the value assigned to list[j] by always adding 1 to i before the assignment.
    Last edited by elad; 06-09-2004 at 11:19 AM.

  2. #17
    Registered User
    Join Date
    Jun 2004
    Posts
    8
    excactly, should it be list[i] = i;?

  3. #18
    Registered User
    Join Date
    Jun 2004
    Posts
    8
    Thank you all, everything is right now. tomorrow I will be back with new assignment and new questions

  4. #19
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >excactly, should it be list[i] = i;?
    Yes. And you should be careful with i and j as identifiers. They look strikingly similar in certain commonly used fonts.
    My best code is written with the delete key.

  5. #20
    Registered User big146's Avatar
    Join Date
    Apr 2003
    Posts
    74
    Hmmm, I havent seen this yet, any reason why ?
    Code:
    int _tmain(int argc, _TCHAR* argv[])
    {
    
    	for ( int i = 1; i < 11; i++ ) {
    
    		if( i % 2 == 0)
    			continue;
    
    		cout << i << endl;
    	}
    	return 0;
    }
    Is this not a good practice ?
    He did not say how this was to be done, so I would think this would be the simplest way to do it for a beginner.
    Last edited by big146; 06-10-2004 at 09:10 PM.

  6. #21
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I havent seen this yet, any reason why ?
    Seen what? Modulus to determine even and odd?

    >int _tmain(int argc, _TCHAR* argv[])
    Seeing as how _tmain isn't the standard entry point into a C++ program, and you don't use the arguments that you declare (and barring any funky requirements for you outside of this forum), it should be this:
    Code:
    int main()


    >Is this not a good practice ?
    I don't see any problem, stylistically, with the algorithm.
    My best code is written with the delete key.

  7. #22
    Registered User big146's Avatar
    Join Date
    Apr 2003
    Posts
    74
    Thx for the reply. But what I meant was since he only had to have the program list number 1 thru 10 and then output the odd ones. Why something like the code I posted was not used? It seems simple enough for someone starting out.He didnt specify how to get the numbers just that he had too,that is all.Aslo i just let visual studio genrate the app for me..I was feeling to lazy to add a cpp.But normaly i do add my own with int main().

    thks
    big146
    big146

  8. #23
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Why something like the code I posted was not used?
    Because the original question was how to write 10 numbers to a list and then remove the odd numbers. That suggests saving intermediate values (as in an array) rather than the test and print solution you posted.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  2. What are some good beginner programs I shouold make?
    By oobootsy1 in forum C# Programming
    Replies: 6
    Last Post: 08-09-2005, 02:02 PM
  3. Best Free Beginner Online Books/Tutorials?
    By Zeusbwr in forum C++ Programming
    Replies: 2
    Last Post: 10-12-2004, 05:52 PM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM