none
homework question RRS feed

Answers

  • Dynojosa as i see your code i see 1 potentionally logical mistake and a compiler error that will occur by running the code:

    i'd like to point out that what your are doing is printing the results, and at the end you seem to place on the undefined results array, at it's nonexistent cell number 6 the value of n * 6. The correct by me is the following (now i have to show the code i have in my mind)

    Console.WriteLine("Please enter a number: \n");
                int n = int.Parse(Console.ReadLine());
                // also up here you need to define the results array and configure it (how many cells).
                int[] results = new int[6];
                for (int i = 0; i <= 5; i++)
                {
    
                    Console.WriteLine(n + "*" + i + "=" + n * i);
                    // you said store the data in the results array so:
    
                    results[i] = n * i;
    
                }
    
                // This shouldn't be here
                //results [i] = n * i;
                
    
                Console.ReadKey();   

    Now i don't know if you have to print it there but i would do it on a different loop and just print the results array like so:

    for (int i = 0; i <= 5; i++)
    {
        Console.WriteLine(results[i]);
    }

    I would do that just to be safe. Note that by not defining the results array you will get a compiler error so that is also a syntax mistake. Be careful with those, because they could really destroy you.

    Please mark as answer any reply that helped you resolve your issue to help others with the similar or same problem finding a solution. Also vote up any reply that was usefull.

    Best Regards,

    Konstantinos Pap

    UPDATED: A mistake on the array declaration. It should be int[] results = new int[6] instead of 5. Sorry for that.


    Tuesday, March 27, 2018 7:53 PM
  • Hi Dynojosa,

    Thank you for providing code.
    Here's my sample:
         
    {
    // -- define array
    int[] aryResult = new int[5];
    int readValue;
    // --- get input data
    Console.Write("Please enter a number: \n");
    readValue = int.Parse(Console.ReadLine());
    // -- loop 5 times: store result
    for (int i = 0; i < 5; i++)
    	{
    	// -- store input data
    	aryResult[i] = readValue * (i + 1);
    	}
    // -- loop 5 times: write result
    Console.WriteLine("--- result ---");
    for (int i = 0; i < 5; i++)
    	{
    	Console.WriteLine(readValue + " x " + (i + 1) + " =  " + aryResult[i]);
    	}
    Console.ReadLine();
    }
    

    Regards,

    Ashidacchi -- http://hokusosha.com/

    Tuesday, March 27, 2018 11:27 PM

All replies

  • Hi Dynojosa,

    I'm afraid you need to provide your code. If you don't have any code, you need to explain how you think to get the results.

    Regards,


    Ashidacchi -- http://hokusosha.com/

    • Edited by Ashidacchi Tuesday, March 27, 2018 6:39 PM
    Tuesday, March 27, 2018 6:38 PM
  • Hello Dynojosa,

    As i understand you are asking the end user for a number. Let's call it num. You will multiply it with the values 0 to 5 so you have a for loop that loops 6 times like so for(int i = 0; i <= 5; i++). After that you want to store the data to an array. Probably like this: you will define the array outside of the loop and in the loop you will set each row to num * i. That means you have array[i] = num * i. Then i don't know what you want to do with the array but that is what i'd do after reading this exercise. I would provide you the full code, but since it is an assignment i won't.

    Hope this gets you on the right track.

    Best Regards,

    Konstantinos Pap

    Updated: Loops 6 times instead of 5. (misstype)

    Tuesday, March 27, 2018 6:48 PM
  •  Console.WriteLine("Please enter a number: \n");
                int n = int.Parse(Console.ReadLine());
                for (int i = 0; i <= 5; i++)
                {

                    Console.WriteLine(n + "*" + i + "=" + n * i);


                }

                
                results [i] = n * i;
                

                Console.ReadKey();   
    Tuesday, March 27, 2018 7:30 PM
  • This does help thank you.
    Tuesday, March 27, 2018 7:30 PM
  • Dynojosa as i see your code i see 1 potentionally logical mistake and a compiler error that will occur by running the code:

    i'd like to point out that what your are doing is printing the results, and at the end you seem to place on the undefined results array, at it's nonexistent cell number 6 the value of n * 6. The correct by me is the following (now i have to show the code i have in my mind)

    Console.WriteLine("Please enter a number: \n");
                int n = int.Parse(Console.ReadLine());
                // also up here you need to define the results array and configure it (how many cells).
                int[] results = new int[6];
                for (int i = 0; i <= 5; i++)
                {
    
                    Console.WriteLine(n + "*" + i + "=" + n * i);
                    // you said store the data in the results array so:
    
                    results[i] = n * i;
    
                }
    
                // This shouldn't be here
                //results [i] = n * i;
                
    
                Console.ReadKey();   

    Now i don't know if you have to print it there but i would do it on a different loop and just print the results array like so:

    for (int i = 0; i <= 5; i++)
    {
        Console.WriteLine(results[i]);
    }

    I would do that just to be safe. Note that by not defining the results array you will get a compiler error so that is also a syntax mistake. Be careful with those, because they could really destroy you.

    Please mark as answer any reply that helped you resolve your issue to help others with the similar or same problem finding a solution. Also vote up any reply that was usefull.

    Best Regards,

    Konstantinos Pap

    UPDATED: A mistake on the array declaration. It should be int[] results = new int[6] instead of 5. Sorry for that.


    Tuesday, March 27, 2018 7:53 PM
  • Dynojosa,

    Be aware that real experts don't help with code for homework. 

    Arrays are beside for fixed arrays like bitmaps not used anymore in C#. It are generic collections currently. 

    Probably you get it in future, but for that you need to have some basic knowledge for arrays. 

    Therefore don't ask for code for homework in forums. Only beginners will help you with code and maybe those answers are not what your teacher expect.


    Success
    Cor



    Tuesday, March 27, 2018 8:51 PM
  • Hi Dynojosa,

    Thank you for providing code.
    Here's my sample:
         
    {
    // -- define array
    int[] aryResult = new int[5];
    int readValue;
    // --- get input data
    Console.Write("Please enter a number: \n");
    readValue = int.Parse(Console.ReadLine());
    // -- loop 5 times: store result
    for (int i = 0; i < 5; i++)
    	{
    	// -- store input data
    	aryResult[i] = readValue * (i + 1);
    	}
    // -- loop 5 times: write result
    Console.WriteLine("--- result ---");
    for (int i = 0; i < 5; i++)
    	{
    	Console.WriteLine(readValue + " x " + (i + 1) + " =  " + aryResult[i]);
    	}
    Console.ReadLine();
    }
    

    Regards,

    Ashidacchi -- http://hokusosha.com/

    Tuesday, March 27, 2018 11:27 PM
  • Arrays are beside for fixed arrays like bitmaps not used anymore in C#. It are generic collections currently.

    Btw, I found that I am still using ordinary array a lot when I don't need the extra facilities offered in LINQ.

    Although List<T> uses ordinary array underneath, the constructor involving IEnumerable<T> uses .CopyTo() to copy the elements inside the array does incur a little cost over ordinary array if that is what you have in the beginning.

    Wednesday, March 28, 2018 1:45 AM
    Answerer
  • Thank you that is good to know, I will keep that in mind when I am out in the field. Today I am just learning the basics but hope to improve and be as advanced as you. 

    Diane Ynojosa

    Wednesday, March 28, 2018 7:29 AM
  • This is good info and really help me see what I was doing wrong. Unfortunately, at my school, there is no tutor to ask for this kind of help so thank you for your help.

    Diane Ynojosa

    Wednesday, March 28, 2018 7:31 AM
  • I appreciate the word of wisdom. I will take them into consideration and be assured that I will only be looking at the examples and taking what I need from it. Thank you for looking out for me.

    Diane Ynojosa

    Wednesday, March 28, 2018 7:34 AM
  • Great feed back

    Diane Ynojosa

    Wednesday, March 28, 2018 7:35 AM
  • In my code suggestion i had a mistake i didn't actually see on the first time. So when i declare the int array i declared it with the computer logic. When declaring an array you declare it with human logic, and when i say human logic i mean how many cells i wanna have ? 6? So you'll put 6 in the brackets. When looping the array you have to do it with computer logic. You will loop from 0 to 5 because the first cell is the 0 with computer logic. Also one more thing when you say multiply that number from 0 through 5 i guess you mean num*0 , num*1 ,... , num*5. If so my suggestion above should do it. Else if you are not including 5 then you want to do it from 0 to 4(of course declare the array with 5 cells if you don't want to include 5). Now in case you don't want to include 0 to your calculation when you multiply it you will have to add one to i. Don't forget to put it in parenthesis because if you don't first it will multiply it by the i and then add one to the result. Personally i think that what is asking is to multiply from 0 to 5 including 0 and 5. So your results would be :

    num * 0 = 0

    num * 1 = ...

    num * 2 = ...

    num * 3 = ...

    num * 4 = ...

    num * 5 = ...

    But it is your choice on what you choose. Hope this helps you and sorry for the mistake above. I updated my reply to the right value.

    Best Regards,

    Konstantinos Pap

    Wednesday, March 28, 2018 12:24 PM